Home All Groups Group Topic Archive Search About

Using an ASPX file as a Script Source

Author
22 Aug 2006 4:56 PM
Moskie
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.

Author
22 Aug 2006 5:11 PM
Peter Bromberg [C# MVP]
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




Show quote
"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.
>
>
Author
22 Aug 2006 6:16 PM
Laurent Bugnion
Hi,

Peter Bromberg [C# MVP] 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.

And also set the Response.ContentType to "text/javascript" ?

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
Author
22 Aug 2006 6:23 PM
Moskie
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.
> >
> >
Author
22 Aug 2006 9:03 PM
Kevin Jones
> 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.


Your gut is right - the browser sends a new request to get the
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.
>>>
>>>
>
Author
22 Aug 2006 9:53 PM
Laurent Bugnion
Moskie wrote:

<snip>

> 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.

Why not use a query string to "pass" parameters to the ASPX page
generating the script file?

<script type="text/javascript"
src="scriptfile.aspx?param1=value1&param2=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

AddThis Social Bookmark Button