Thursday, March 6, 2008


ASP.NET 2.0 AJAX - "Only one instance of a ScriptManager can be added to the page" Error Message


Since I am working extensively with ASP.NET 2.0 AJAX. I like to share a fix for error message indicates "Only one instance of a ScriptManager can be added to the page"!

This happens when you have multiple instance of ScriptManager declared and therefore running at the same time during the life of session. My case was due to the fact that I applied master page to my ASP.net web forms. I also built Web User Controls to embed in these web forms which most of them have AJAX controls as part of web user controls. Well, previously, you have to specifically declare

ajax:ToolkitScriptManager runat="Server" EnableScriptGlobalization="true"
EnableScriptLocalization="true" ID="ScriptManager1" />

prior to declare AJAX controls on each page. The problem resided that the scope become nested when you have AJAX declared Web User Control in the master page while other web forms also have their own AJAX Web User Controls in them. Do you see the issue? You have multiple instances of ScriptManager running at the same time!

The fix: simply remove all child AJAX ScriptManager declarations and place only one in the root or where your master page(if you use it to sync your web forms). This should resolve the issue of "Only one instance of a ScriptManager can be added to the page"!

Hope this help...

Cheers!


Bookmark and Share


2 comments:

Anonymous said...

Problem: "ASP.NET 2.0 AJAX - "Only one instance of a ScriptManager can be added to the page" Error Message"

Situation: This error message also applies to those who are "so clever like me" that add the web page separately and linked to a master page by using a text file (rename to .aspx,) or insert a web page from (out of the project) file, or inserted a web form.

Solution: Use Ajax Web Form.

Explanation: If you already have a master page on your project, and you already insert the script manager and using the Ajax somewhere, please insert the “Ajax” web form. Do not use a normal web form.

David Chen(DJ Skyline) said...

Thanks alot for contributing!
Yep, its true that this scenario is quite common when dealing with multiple page/layer architecture and in your "clever" approach :) Just fall on the same situation as mine!
BTW, I totally agree with your Explanation, as I didn't really applied all my other web forms as AJAX enabled which means that it can't have more than one instance of ScriptManager on the child web forms. Please come by more often to share with us in this aspect,thanks so much!