|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using an ASPX file as a Script SourceI recently came across an application where the 'src' attribute of a
script tag was an ASPX file. Like so: <script language="JavaScript" src="scriptfile.aspx"></script> This is a new idea for me, and I had some questions about it. When scriptfile.aspx is processed, is it going to have access to the same request object and submitted form variables that the parent page has? Will that aspx page be able to access the public and protected members with <% %> server tags as the parent page would? And maybe someone can link me to a guide on the web that details what can and can't be done in this situation. Thanks. If you are going to emit Javascript from an ASPX page, you will need to
remove everything in the ASPX (Html page) portion except the <@page declaration at the top. In your Page_Load EventHandler, that is where you would Response.Write the string of script. -- Show quoteCo-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com "Moskie" wrote: > I recently came across an application where the 'src' attribute of a > script tag was an ASPX file. Like so: > > <script language="JavaScript" src="scriptfile.aspx"></script> > > This is a new idea for me, and I had some questions about it. > > When scriptfile.aspx is processed, is it going to have access to the > same request object and submitted form variables that the parent page > has? Will that aspx page be able to access the public and protected > members with <% %> server tags as the parent page would? > > And maybe someone can link me to a guide on the web that details what > can and can't be done in this situation. > > Thanks. > > Hi,
Peter Bromberg [C# MVP] wrote: > If you are going to emit Javascript from an ASPX page, you will need to And also set the Response.ContentType to "text/javascript" ?> remove everything in the ASPX (Html page) portion except the <@page > declaration at the top. > In your Page_Load EventHandler, that is where you would > Response.Write the string of script. HTH, Laurent -- Laurent Bugnion, GalaSoft Software engineering: http://www.galasoft-LB.ch PhotoAlbum: http://www.galasoft-LB.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch That much I understand.
My questions are pertaining to what I actually have access to when that aspx page is processing (i.e. in the Page_Load handler). Do I have access to the same Requset object as the parent page (the page with the script tag)? Or is this going to be a whole new request with a whole new request object? My gut tells me that this is going to be whole new request, and I have no way to "pass" anything to it when it is being requested via a script tag.... unless ASP.Net is doing something weird that I'm not aware of. Peter wrote: Show quote > If you are going to emit Javascript from an ASPX page, you will need to > remove everything in the ASPX (Html page) portion except the <@page > declaration at the top. > In your Page_Load EventHandler, that is where you would > Response.Write the string of script. > > -- > Co-founder, Eggheadcafe.com developer portal: > http://www.eggheadcafe.com > UnBlog: > http://petesbloggerama.blogspot.com > > > > > "Moskie" wrote: > > > I recently came across an application where the 'src' attribute of a > > script tag was an ASPX file. Like so: > > > > <script language="JavaScript" src="scriptfile.aspx"></script> > > > > This is a new idea for me, and I had some questions about it. > > > > When scriptfile.aspx is processed, is it going to have access to the > > same request object and submitted form variables that the parent page > > has? Will that aspx page be able to access the public and protected > > members with <% %> server tags as the parent page would? > > > > And maybe someone can link me to a guide on the web that details what > > can and can't be done in this situation. > > > > Thanks. > > > > > My gut tells me that this is going to be whole new request, and I have Your gut is right - the browser sends a new request to get the > no way to "pass" anything to it when it is being requested via a script > tag.... unless ASP.Net is doing something weird that I'm not aware of. javascript file. You *could* store bits in session and process them when the request comes back in but this seems like a horrible kludge to me, Moskie wrote: Show quote > That much I understand. > > My questions are pertaining to what I actually have access to when that > aspx page is processing (i.e. in the Page_Load handler). Do I have > access to the same Requset object as the parent page (the page with the > script tag)? Or is this going to be a whole new request with a whole > new request object? > > My gut tells me that this is going to be whole new request, and I have > no way to "pass" anything to it when it is being requested via a script > tag.... unless ASP.Net is doing something weird that I'm not aware of. > > Peter wrote: >> If you are going to emit Javascript from an ASPX page, you will need to >> remove everything in the ASPX (Html page) portion except the <@page >> declaration at the top. >> In your Page_Load EventHandler, that is where you would >> Response.Write the string of script. >> >> -- >> Co-founder, Eggheadcafe.com developer portal: >> http://www.eggheadcafe.com >> UnBlog: >> http://petesbloggerama.blogspot.com >> >> >> >> >> "Moskie" wrote: >> >>> I recently came across an application where the 'src' attribute of a >>> script tag was an ASPX file. Like so: >>> >>> <script language="JavaScript" src="scriptfile.aspx"></script> >>> >>> This is a new idea for me, and I had some questions about it. >>> >>> When scriptfile.aspx is processed, is it going to have access to the >>> same request object and submitted form variables that the parent page >>> has? Will that aspx page be able to access the public and protected >>> members with <% %> server tags as the parent page would? >>> >>> And maybe someone can link me to a guide on the web that details what >>> can and can't be done in this situation. >>> >>> Thanks. >>> >>> > Moskie wrote:
<snip> > My gut tells me that this is going to be whole new request, and I have Why not use a query string to "pass" parameters to the ASPX page > no way to "pass" anything to it when it is being requested via a script > tag.... unless ASP.Net is doing something weird that I'm not aware of. generating the script file? <script type="text/javascript" src="scriptfile.aspx?param1=value1¶m2=value2"></script> HTH, Laurent -- Laurent Bugnion, GalaSoft Software engineering: http://www.galasoft-LB.ch PhotoAlbum: http://www.galasoft-LB.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch |
|||||||||||||||||||||||