Dynamically creating a .js file to be included in response

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

Dmitriy Lapshin [C# / .NET MVP]

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

Ron Vecchi

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

Dmitriy Lapshin [C# / .NET MVP]

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

Jacob Yang [MSFT]

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

Ron Vecchi

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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top