I am looking at an asp.net 2 web application that I am maintaining (but did not write).
Some things that should happen on the page loading do not, but only sometimes, and it seems to be if you are using Firefox 3 inside a VM. JQuery and asp.net Ajax are used.
The important function that should run every time (but does not) is attached by the following Javascript:
<script type='text/javascript'> //<![CDATA[ $(document).ready(function(){ Sys.Application.add_load(ImportantFunction); }); $(document).ready(function(){ Otherstuff(); }); $(document).ready(function(){ MoreStuff(); }); //]]> </script>
But if I use firebug to set a breakpoint inside ImportantFunction(), it is not hit on page load in firefox 3, but it is hit on an ajax update.
In the page there are multiple calls to $(document).ready since they come from different parts of the asp.net code behind it. Yes, they do all execute.
Try this:
Put the call to
Sys.Application.add_loadin the body ofImportantFunction, i.e in your .js file:Edit: I’m not sure if its possible to add multiple functions to be run on
$(document).readyevent. It might help if you did this instead:And in
inityou can include calls to all the other functions, i.e:It will also make the code easier to read 🙂