I am using ASP.NET MVC, Partial Views and Dialogs. I make a ajax request to the server and it hands me back a partial view. Then I use: $('#elementTag').html(returnData) to refill the bounding div's. However, this partial view contains the inner working for a dialog wrapped in a form element along with the rest of the partial view content. The javascript also contained within the partial view, upon document ready would sets up the dialog.
I started on this design method: bundling the dialog content along with the partial view to keep things together.
Now I started on this issue because I was having problems with one of my dialogs. I could initialize a form element within a dialog form prior to showing the dialog but, when the user requested to save the data from the dialog all elements retreived using a serializeArray were empty.
Using Firebug I noticed that each time I requested the partial view containing the dialog form it was creating another form of the same type (i.e. definetly a memory leak there). My html was being replaced and I beleive that the script was also being duplicated.
So either I am doing this all wrong or there is a problem here. I am using the modal dialog to prompt for information, serializing the data from the dialog and sending it to the server.
What is the best practice here? Should I bundle all the dialog content into the site master and all the javascript into a single js file or is there a way to replace everything?