Click to See Complete Forum and Search --> : Change Update Panel: Javascript Grows


eeve
04-08-2008, 02:35 PM
Hello,

My question might be either very simple or very complex. I hope someone can point me in the right direction. Thanks!

I noticed when I view the Generated Source of my C#.NET web application, that the Javascript that was added to the ScriptManager, as well as various entries like this:

Sys.WebForms.PageRequestManager._addArrayElement('Page_Validators', document.getElementById("ctl00_ <snip.....>

Get's appended to the page each time I change my update panel or reload the page or switch pages. So I get the same Javascript functions defined multiple times. I need to know how to either clear this out, or prevent it from appending. Since my javascript has to use the ClientID of the controls, I need to add the javascript from within the UserControl and not use a global js file.

My application structure is rather complex:

ApplicationChrome.master
->contains a ScriptManager.
->contains a Page: MainPage.aspx.
MainPage.aspx
->Contains a very complex asp:TreeView control and,
->Contains an UpdatePanel
The UpdatePanel
->Contains a UserControl (ManageWidgets.ascx, ManageUsers.ascx, Home.ascx, etc.)
ManageWidgets.ascx
->Contains form fields with custom validators.
->The code-behind registers the validator JS code in OnPreRender().


Based on what action you select in the TreeView, the UpdatePanel is changed to have a different UserControl.

This prevents the tree from being re-rendered when you navigate around. The user controls act basically like pages INSIDE a frame.

The code-behind for the UserControl: ManageWidgets.ascx.cs attaches the javascript for the custom Validators inside it's OnPreRender() method like so:

ScriptManager.RegisterClientScriptBlock(this, typeof(ManageWidgets), "ManageWidgetsJS", scriptStr, true);

I've tried turning partial page rendering on and off, tried moving the ScriptManager into the UserControl rather than having it in the master page. Tried putting the JS directly into the ManageWidgets.ascx html code. Nothing.

It's not just the Registered script block that is being repeated, but also the validator JS that .net creates. Basically it just keeps growing as you navigate around the pages via the tree. So you end up with ManageWidgets JS on the page for ManageUsers. And the site gets progressively slower.

Sorry for how complex this is, but hopefully someone will take on this challenge! Thanks so much!

rrrrrrr
07-29-2008, 11:31 PM
howdy,

I am having the same issue almost exactly as you describe except no tree view involved ... did you have any luck resolving this problem?

regards