?
Solved

Problem with ScriptManager

Posted on 2014-08-13
7
Medium Priority
?
361 Views
Last Modified: 2014-08-13
Hi,
due to some reason, I do need 2 ScriptManager within the Markup page like

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <cc1:ToolkitScriptManager runat="server"></cc1:ToolkitScriptManager>
    ...

Open in new window

but I've got this due to the above. Any ideas?

Server Error in '/App9' Application.

Only one instance of a ScriptManager can be added to the page.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Only one instance of a ScriptManager can be added to the page.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[InvalidOperationException: Only one instance of a ScriptManager can be added to the page.]
   System.Web.UI.ScriptManager.OnInit(EventArgs e) +868
   System.Web.UI.Control.InitRecursive(Control namingContainer) +186
   System.Web.UI.Control.InitRecursive(Control namingContainer) +314
   System.Web.UI.Control.InitRecursive(Control namingContainer) +314
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2098

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446

Open in new window

0
Comment
Question by:HuaMinChen
  • 4
  • 3
7 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 660 total points
ID: 40257730
Well the error message says it all. You cannot have multiple ScriptManager components in the same page.
To overcome this I know you can use the ScriptManagerProxy

The main Idea is to have one ScriptManager on the MasterPage and one ScriptManagerProxy on each component that needs it.

Anyway, I don't know what you're trying to accomplish but cou migh also consider putting your javascript in a .js file and pass the server-side information in input hidden fields. Like this you don't inject javascript, it's the javascript that reads the values in the input hidden fields and act accordingly.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40257738
Thanks. can I have more details to put one ScriptManager into "ScriptManagerProxy"?
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40257745
Hi mate,
right now I cannot write you a ASP.net sample for this but I've found this blog entry that I believe explains it pretty well:
http://pavanarya.wordpress.com/2011/12/26/scriptmanagerproxy-and-its-usage/

ScriptManagerProxy it's like the ScriptManager but relays the script from the child controls the the ScriptManager on the MasterPage.
Also make sure you declare your ScriptManager right at the beginning of the page, before any ScriptManagerProxy is used.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:HuaMinChen
ID: 40257763
Sorry Alexandre.
do I need one other .ascx page to that ScriptManagerProxy? which part of my current aspx page should be removed into this ScriptManagerProxy?
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40257766
Just to clear out:

<cc1:ToolkitScriptManager runat="server"></cc1:ToolkitScriptManager>
is a custom control that you did that has a ScriptManager inside right?
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 40257768
That Toolkit is for Ajax, due to this line

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
...

Open in new window

0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40257801
Ah, sorry mate, missed that ToolkitScriptManager, never used it.

I read a bit about it and it seems that the solution goes around these lines:
Remove ScriptManger from your Master Page and add a ToolScriptManager control to each of the Parent pages of your controls and then add a ScriptManagerProxy to your UserControls if needed
So basically what you need to do is:
Remove the ScriptManager from the master page (just don't use it anywhere)
Add the ToolkitScriptManager to the master page
Use the ScriptManagerProxy instead in the child pages that currently need the ScriptManager
As I told you I can't test this but it looks like it works.

As a reference I read the main idea from here: http://forums.asp.net/t/1120457.aspx?ToolkitScriptManager+and+ScriptManagerProxy
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question