This is a migrated thread and some comments may be shown as answers.

ScriptManager problems (solution)

2 Answers 161 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jimmy
Top achievements
Rank 1
Jimmy asked on 27 Mar 2009, 10:24 AM

Hey folks.

For you guys struggling with one of the following errors (or both if you try to render a new ScriptManager)
 
 - Only one instance of a ScriptManager can be added to the page.
 - The control with ID 'xx' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

The solution is to make sure that the ScriptManager is rendered BEFORE the given RAD Control, and that only one ScriptManager exists. The following code snippet should achive this:

protected override void CreateChildControls()
{
     if (ScriptManager.GetCurrent(this.Page) != null)
     {

          this.sm = ScriptManager.GetCurrent(this.Page);
     }
     else
     {
          this.sm = new ScriptManager();
          this.Controls.Add(this.sm);
     }
}

Now make sure the ScriptManager is rendered BEFORE the controls needing it (ie RadEditor)

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
     this.sm.RenderControl(writer);
     this.radEditor.RenderControl(writer);
}

Hopefully this will be helpful to someone else.

2 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 27 Mar 2009, 05:38 PM
Thanks for the code snippets, Jimmy!

An alternate "declarative" approach is to simply place the ScriptManager on your MasterPage (right below the opening server Form tag). Then, on child pages or UserControls that need to interact with the ScriptManager, simply use the ScriptManagerProxy control. That will help you avoid both errors in your application.

Either way, happy to hear you've found a solution. Enjoy the RadControls!

-Todd
0
Jimmy
Top achievements
Rank 1
answered on 30 Mar 2009, 07:39 AM
Hi Todd.

My pleasure :)

Thank you for posting your alternative solution. In my situation I wasn't allowed to modify the master page. I'm developing WebParts for SharePoint and such compontents are supposed to work in a lot of different environments.

Regards
Jimmy Thomsen
Tags
General Discussions
Asked by
Jimmy
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Jimmy
Top achievements
Rank 1
Share this question
or