More in this section

Forums / General Discussions / UpdatePanel in MasterPage causes error

UpdatePanel in MasterPage causes error

8 posts, 0 answered
  1. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    22 Oct 2010
    Link to this post
    I have an UpdatePanel in my MasterPage and I get the following error

    Cannot unregister UpdatePanel with ID 'UpdatePanel1' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported.

    This article seemed relevant

    Any ideas?

    Thanks,
    Eric
  2. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    23 Oct 2010
    Link to this post
    Hold off on looking into this. Both the MasterPage and a custom control both had an UpdatePanel with the same name. I removed the one from the MasterPage and I still had the issue.

    On Monday, I'll remove the UpdatePanel from control and see what happens. Then maybe I'll add it back to MasterPage and try it.

    I'll let you know what I find...
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Oct 2010
    Link to this post
    Hi Eric,

    Try using RadAjaxPanel with ScriptManager declared inside a control

    <asp:ScriptManager ID="ScriptManager" runat="server"/>
    <telerik:RadAjaxPanel id="RadAjaxPanel1" runat="server" EnableAJAX= "True">
      <asp:Label ID="Label1" runat="server" /><br />
      <asp:Button ID="Button2" runat="server" Text="Update" OnClick="Button1Test_Click" />
    </telerik:RadAjaxPanel>


    code behind

    protected void Button1Test_Click(object sender, EventArgs e)
          {
              Label1.Text = DateTime.Now.ToLongTimeString();
           
          }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    25 Oct 2010
    Link to this post
    Over the weekend, I saw this was an issue with 3.x also.

    I create my controls in a separate project and then import them into my Sitefinity site (by copying the DLL and ASCXes). My understanding of the license of the RadControls bundled with Sitefinity, would not permit this. Is that correct?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Oct 2010
    Link to this post
    Hello Eric,

    This issue is not related the the license. Do you have a problem when you use RadAjaxPanel and ScriptManager as my code shows?

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    25 Oct 2010
    Link to this post
    With that code, I keep getting a null reference exception

    [NullReferenceException: Object reference not set to an instance of an object.]
    Telerik.Web.UI.RadAjaxControl.OnPagePreRender(Object sender, EventArgs e) +282
    
    
    I get the same error if I switch the RadAjaxPanel with a regular Panel and add a RadAjaxManager.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Oct 2010
    Link to this post
    Hi Eric,

    I cannot  reproduce this issue if I add the control inside the template from the backend UI or drop the control on a page, so you can use these options. The issue only appears if you hardcode the controls inside the .master file and we are going to investigate this issue.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Eric
    Eric avatar
    147 posts
    Registered:
    12 Nov 2007
    25 Oct 2010
    Link to this post
    I have a workaround that seems to work, though I worry it may lead to memory leaks or something. In my ControlBase (which all my controls inherit from), when the control initializes, I check to see if the control is on a Sitefinity page and if it's in design mode, if so, I add an onload event handler to the each update panel in the control (using a Control extension method: FindControls). The event handler adds the UpdatePanel to the ScriptManager again, this time from when the control is in its final resting place.

    This seems to work, but I don't know the inner workings of ASP.NET and the ScriptManager enough to know whether this causes any issues.

    I took this approach from the comment made by Philippe on

    The other method that worked was to create a new class that inherited from UpdatePanel and then override the OnUnload method and not call the base method -- at least not when it resided on a Sitefinity page and in design mode. I preferred the first method because I didn't have to change my code (even if I just had to do a massive search and replace of "asp:UpdatePanel" with "my:MyUpdatePanel" or something).

    protected override void OnInit(EventArgs e)
    {
        if (Page is SitefinityRadPage && Page.IsDesignMode())
        {
            foreach (UpdatePanel up in this.FindControls<UpdatePanel>())
            {
                up.Load += UpdatePanel_Load;
            }
        }
     
        base.OnInit(e);
    }
     
    private void UpdatePanel_Load(object sender, EventArgs e)
    {
        UpdatePanel panel = sender as UpdatePanel;
     
        MethodInfo m = (from methods in typeof(ScriptManager).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
                                where methods.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")
                        select methods).First();
     
        if (panel == null || m == null)
        {
                    return;
        }
     
        m.Invoke(ScriptManager.GetCurrent(Page), new object[] { panel });
    }

    Eric
8 posts, 0 answered