Dynamically creating a .js file to be included in response

  • Thread starter Thread starter Ron Vecchi
  • Start date Start date
R

Ron Vecchi

I am creating a custom web control that uses an enum for a property
{Remote,InLine}.
If the property is set to inline then text is read from the embedded
resource and sent to the browser in the aspx page as inline java script.
If the property is set to Remote then the script tag set with the SRC
attribute is displayed <script language="javascript"
Src="MyJS.js"></script>.

Is there a way to catch an incoming request from the browser (for the
<script language="javascript" src="myJavaScript.js"></script>
And then dynamically create the file before it returns a response to the
browser that the file does not exsit


Thanks,
Ron.
 
Hi,

Sleight of hand: specify an aspx file in the SRC attribute of the SCRIPT tag
and generate the script on the fly in this aspx file.
 
One problem with that is that now I would need to have an aspx file along
with my custom control.
I have recently caught notice of HttpHandlers but really don't know what
they are or how to use them.




Dmitriy Lapshin said:
Hi,

Sleight of hand: specify an aspx file in the SRC attribute of the SCRIPT tag
and generate the script on the fly in this aspx file.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ron Vecchi said:
I am creating a custom web control that uses an enum for a property
{Remote,InLine}.
If the property is set to inline then text is read from the embedded
resource and sent to the browser in the aspx page as inline java script.
If the property is set to Remote then the script tag set with the SRC
attribute is displayed <script language="javascript"
Src="MyJS.js"></script>.

Is there a way to catch an incoming request from the browser (for the
<script language="javascript" src="myJavaScript.js"></script>
And then dynamically create the file before it returns a response to the
browser that the file does not exsit


Thanks,
Ron.
 
Ron,

In case of Http handlers I beleive you'll still have to have an additional
handler file (don't remember its extension) - or at least modify the
application's web.config file to register the handler.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ron Vecchi said:
One problem with that is that now I would need to have an aspx file along
with my custom control.
I have recently caught notice of HttpHandlers but really don't know what
they are or how to use them.




Dmitriy Lapshin said:
Hi,

Sleight of hand: specify an aspx file in the SRC attribute of the SCRIPT tag
and generate the script on the fly in this aspx file.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Ron Vecchi said:
I am creating a custom web control that uses an enum for a property
{Remote,InLine}.
If the property is set to inline then text is read from the embedded
resource and sent to the browser in the aspx page as inline java script.
If the property is set to Remote then the script tag set with the SRC
attribute is displayed <script language="javascript"
Src="MyJS.js"></script>.

Is there a way to catch an incoming request from the browser (for the
<script language="javascript" src="myJavaScript.js"></script>
And then dynamically create the file before it returns a response to the
browser that the file does not exsit


Thanks,
Ron.
 
Hi Ron,

Firstly I wan to thank Dmitriy for this great help in this issue.

Based on my research and experience, we need not to create our own
httphandler or httpmoudle in this case. As my opinion, since we know when
the enum propery is equal to Remote,InLine or when it equal to another
value, we can decide whether we need to generate the js file at that time
on the fly.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Yes, It took me a little while to think through it but since the enum is
known I basically check for it and then create a directory and the .js file
on the server and render my control with the <Script> tag either with the
src attribute pointed to the newly created file or with the tag and
javascript all togeather on the page.

Thanks
 
Back
Top