ScriptManager problems (solution)

3 posts, 0 answers
  1. Jimmy
    Jimmy avatar
    22 posts
    Member since:
    Nov 2008

    Posted 27 Mar 2009 Link to this post

    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. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 27 Mar 2009 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jimmy
    Jimmy avatar
    22 posts
    Member since:
    Nov 2008

    Posted 30 Mar 2009 Link to this post

    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
Back to Top