Using an ASPX file as a Script Source

M

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

Guest

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

Laurent Bugnion

Hi,
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
 
M

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

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,
 
L

Laurent Bugnion

Moskie wrote:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,269
Messages
2,571,098
Members
48,773
Latest member
Kaybee

Latest Threads

Top