Problem with ScriptManager

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

LVL 11
HuaMin ChenProblem resolverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alexandre SimõesManager / Technology SpecialistCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HuaMin ChenProblem resolverAuthor Commented:
Thanks. can I have more details to put one ScriptManager into "ScriptManagerProxy"?
0
Alexandre SimõesManager / Technology SpecialistCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

HuaMin ChenProblem resolverAuthor Commented:
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
Alexandre SimõesManager / Technology SpecialistCommented:
Just to clear out:

<cc1:ToolkitScriptManager runat="server"></cc1:ToolkitScriptManager>
is a custom control that you did that has a ScriptManager inside right?
0
HuaMin ChenProblem resolverAuthor Commented:
That Toolkit is for Ajax, due to this line

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

Open in new window

0
Alexandre SimõesManager / Technology SpecialistCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.