What is the best way to programmatically run javascript when an ASP.net page loads?
Posted
by Rising Star
on Stack Overflow
See other posts from Stack Overflow
or by Rising Star
Published on 2010-06-03T17:56:59Z
Indexed on
2010/06/03
18:04 UTC
Read the original article
Hit count: 144
ASP.NET
|JavaScript
In my global.asax
file for my ASP.net project, I am checking for certain conditions. When those conditions are met, I want to automatically execute javascript code when the page runs.
This is my code:
if condition Then
Response.Write("")
Response.Write(" // Javascript code to do stuff ")
Response.Write("")
End If
While this appears to work to execute the Javascript code, I don't think it's a best practice because this code will preceed all of the HTML of the page that gets loaded.
What is the best way of programmatically tacking on some extra Javascript code to be run when my page loads?
© Stack Overflow or respective owner