I'm getting a very peculiar problem with my asp.net application, it took me an age to track down but I still don't know what is causing this behaviour.
If I set a session variable in the Application_PreRequestHandlerExecute
event, then my external JavaScript files are ignored, and therfore causing a raft of errors. I have simplified the problem below.
E.g.
I have file called JScript.js
containing the code:
function myAlert() {
alert("Hi World");
}
And in my Default.aspx
file I reference the js with the code:
<script src="JScript.js" type="text/javascript"></script>
And in the body onload
event I call the myAlert()
function:
<body onload="myAlert()">
And finally in the Global.asax
file:
Private Sub Application_PreRequestHandlerExecute(ByVal sender As Object, ByVal e As EventArgs)
HttpContext.Current.Session("myVar") = "MyValue"
End Sub
If you run the Default.aspx
file you will see the js function isnt called, however, if you comment out the line of code Global.asax
then the external js is called and the function executed when the page loads.
Why is this?