UpdatePanel in MasterPage causes error

Posted by Community Admin on 03-Aug-2018 21:03

UpdatePanel in MasterPage causes error

All Replies

Posted by Community Admin on 22-Oct-2010 00:00

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
http://msmvps.com/blogs/luisabreu/archive/2006/11/16/adding-removing-updatepanels-dynamicaly-from-a-page.aspx

Any ideas?

Thanks,
Eric

Posted by Community Admin on 23-Oct-2010 00:00

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...

Posted by Community Admin on 25-Oct-2010 00:00

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

Posted by Community Admin on 25-Oct-2010 00:00

Over the weekend, I saw this was an issue with 3.x also.

http://www.sitefinity.com/devnet/kb/sitefinity-3-x/cannot-unregister-updatepanel-with-id.aspx

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?

Posted by Community Admin on 25-Oct-2010 00:00

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

Posted by Community Admin on 25-Oct-2010 00:00

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.

Posted by Community Admin on 25-Oct-2010 00:00

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

Posted by Community Admin on 25-Oct-2010 00:00

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
http://msmvps.com/blogs/luisabreu/archive/2006/11/16/adding-removing-updatepanels-dynamicaly-from-a-page.aspx#1646817

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

This thread is closed