Only one instance of scriptmanager can exist on a page

I create ASP.NET web user control, and with the help of masking and scripting, I always get a reference to an object that is not set to an exception instance of the object at runtime.

Stacktrace:

[InvalidOperationException: Only one instance of ScriptManager can be added to the page.] System.Web.UI.ScriptManager.OnInit (EventArgs e) +384613 System.Web.UI.Control.InitRecursive (Control namingContainer) +333 System.Web.UI. Control.InitRecursive (Control namingContainer) +210 System.Web.UI.Control.InitRecursive (Control namingContainer) +210 System.Web.UI.Control.InitRecursive (Control namingContainer) +210 System.Web.UI.Control.InitRecursive (Control namingContainer) +210 System.Web.UI.Control.InitRecursive (Control namingContainer) +210 System.Web.UI.Page.ProcessRequestMain (Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378

What causes this? Thanks

+4
source share
3 answers

Where do you declare ScriptManager - in the UserControl, on the page where the control is located, or in MasterPage?

I would recommend (if possible - the main warning is .NET 3.5 installed on the server) defining the ScriptManager in MasterPage (or page level if you are not using MasterPages), and then using ScriptManagerProxy in your user control:

Includes nested components, such as content pages and user controls, to add script and service links to pages when the ScriptManager control is already defined in the parent element.

Edit to add:

If you cannot use ScriptManagerProxy, then either take a look at the ToolkitScriptManager from the AJAX management toolkit - it gives you many .NET 3.5 ScriptManager features without using 3.5, including the .GetCurrent method:

ScriptManager scriptManager = ToolkitScriptManager.GetCurrent(Page); if (null != scriptManager) { // Create a new ToolkitScriptManager and add it to the page. } 

Alternatively, you can perform this search yourself by iterating through the page control collection that is looking for an instance of ScriptManager.

+2
source

If you use Telerik control, the Script manager cannot work.

We can use either Telerik control or ScriptManager

0
source

I think your mistake is more related to " Only one instance of ScriptManager can be added to a page ."

Check if there are multiple ScriptManager on your page

-1
source

Source: https://habr.com/ru/post/1309646/


All Articles