Hi,
I am implementing a customer database which lets me search for users and companies, browse and edit their details, and many other things using ASP.NET MVC and javascript (jQuery).
Whenever a post or get occurs, I do that via jQuery.load and insert the PartialView into the DOM.
Some partial views include forms. I want those to be ajax forms as well, so those partialviews have document.ready handlers that turn the forms into ajax forms (via jquery.form).
At the beginning I was handling this in the callback / code that inserts the partial view into the DOM. However, this resulted in one big script containing lots of javascript functions that refer to different pages. I refactored the big javascript by inserting the scripts into the respective pages.
Now the code is sleeker (I have much less OnXXXPartialView handlers) and the code is neatly inside the partial view it belongs to. Most of those files only include 3-4 lines of javascript code, so the overhead is not really significant.
So effectively I am not only adding elements to the document DOM, but sometimes I am also adding a piece of javascript. In practice this works fine, but it seems Firebug can't debug the dynamically loaded scripts.
There are ofcourse workarounds the Firebug issue, but I am wondering whether my architecture may be the real culprit here. Where do you put javascript that belongs to partial views? Is there any best practice?