开发者

Only one instance of a scriptmanager can exist on a page

开发者 https://www.devze.com 2022-12-30 17:21 出处:网络
I design an ASP.NET web usercontrol and with a maskeditor and scriptmanager, I always get an object reference not set to an instance of an object exception at runtime.

I design an ASP.NET web usercontrol and with a maskeditor and scriptmanager, I always get an object reference not set to an instance of an object exception at runtime.

Stacktrace is:

[InvalidOperationException: Only one instance of a 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 includeStagesAfterAsyncP开发者_运维知识库oint) +378

What causes this? Thanks


Where are you declaring the ScriptManager - in the UserControl, the Page that host the control, or in a MasterPage?

I'd recommend (if you can - the main caveat is .NET 3.5 installed on the server) defining the ScriptManager in the MasterPage (or page level if you're not using MasterPages), and then using a ScriptManagerProxy in your user control:

Enables nested components such as content pages and user controls to add script and service references to pages when a ScriptManager control is already defined in a parent element.

Edit to add:

If you can't use the ScriptManagerProxy, then either take a look at the ToolkitScriptManager from the AJAX control toolkit - it gives you a lot of the features of the .NET 3.5 ScriptManager without having to use 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 could perform that lookup yourself, by iterating through the Page's control collection looking for a ScriptManager instance.


If you are using Telerik control then Script manager can't work .

We can use either Telerik control or ScriptManager


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

Check if you have more than one ScriptManager on your page

0

精彩评论

暂无评论...
验证码 换一张
取 消