In my file global.asaxfor my ASP.net project, I check for specific conditions. When these conditions are met, I want to automatically execute javascript code when the page starts.
This is my code:
if condition Then Response.Write ("<script type =" "text / javascript" ">")
Response.Write ("// Javascript code to do things")
Response.Write ("</script>")
End If
While this works to execute Javascript code, I donβt think this is the best practice, because this code will precede the entire HTML page of the loaded page.
What is the best way to programmatically bind to some additional Javascript code that will execute when my page loads?
Refresh Thank you for your reply. Too bad this solution does not work out global.asax. Is it impossible to do this on the site? It seems to global.asaxbe the logical place to put the code that runs with each page ... Response.Writeworks fine in global.asax.
source
share