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

WindowManager UpdatePanel issue

1 Answer 88 Views
Window
This is a migrated thread and some comments may be shown as answers.
DvdBrink
Top achievements
Rank 1
DvdBrink asked on 22 Jun 2012, 09:16 AM

Hi guys,

I’m having a issue with a RadWindow which contains an UpdatePanel in combination with the RadWindowManager.

When the popup is added during a GET request it throws an error:

Cannot unregister UpdatePanel with ID 'test' 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.

When I disable the line: “createRadWindow()” it works and the popup is visible.

Why can’t the popup be created during a GET request?

I’ve read this page: http://www.telerik.com/support/kb/aspnet-ajax/window/cannot-unregister-updatepanel-with-id-updatepanelid-since-it-was-not-registered-with-the-scriptmanager.aspx

But I use the RadWindowManager because it recreates the RadWindow from the ViewState in a postback request.

In short I have two questions:
How can I fix this issue? I Need the RadWindowManager to recreate my windows so events for controls on these dialogs work properly.
Why does the popup work when created from a postback and not from a get request.

Kind regards,
DvdBrink

Below is my sample code

 aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikRadWindowIssue.Default" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="upanel" runat="server" ChildrenAsTriggers=false UpdateMode=Conditional>
            <ContentTemplate>
                <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
                </telerik:RadWindowManager>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

CSharp code
using System;
using System.Web.UI;
using Telerik.Web.UI;
 
namespace TelerikRadWindowIssue
{
    public partial class Default : System.Web.UI.Page
    {
 
        protected override void OnInit(EventArgs e)
        {
            ScriptManager1.RegisterAsyncPostBackControl(Button1);
            Button1.Click += new EventHandler(Button1_Click);
 
            createRadWindow(); //With this line enabled the page crashes
            //Disable and click on the button, same code, but the window opens correctly
 
            base.OnInit(e);
        }
 
        void Button1_Click(object sender, EventArgs e)
        {
            createRadWindow();
            upanel.Update();
        }
 
        private void createRadWindow()
        {
            TestWindow window = new TestWindow();
            RadWindowManager1.Windows.Add(window);
        }
 
        private class TestWindow : RadWindow
        {
            public TestWindow()
            {
                ContentContainer.Controls.Add(new UpdatePanel() { ID = "test" });
                VisibleOnPageLoad = true;
                Width = 150;
                Height = 150;
            }
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 26 Jun 2012, 09:49 AM
Hello,

This problem stems from the framework itself as is described in the KB article you have already found. There is a way to work around it, yet the important bit is that the RadWindowManager will not keep the state of the controls inside the RadWindow, but only for the RadWindows themselves. Nevertheless, a simple factory class can add a handler that properly register the update panels you create:
static class DisposableWindowFactory
{
    //you can add parameters to control the properties of the RadWindow
    public static RadWindow CreateDisposableWindow()
    {
        RadWindow newWindow = new RadWindow();
        UpdatePanel disposableUpdatePanel = new UpdatePanel();
        //used for disposing the update panel properly
        disposableUpdatePanel.Unload += new EventHandler(RegisterUpdatePanel);
        disposableUpdatePanel.ID = "DisposableUpdatePanel";
        newWindow.ContentContainer.Controls.Add(disposableUpdatePanel);
        newWindow.VisibleOnPageLoad = true;
        newWindow.Width = 150;
        newWindow.Height = 150;
        return newWindow;
    }
 
    private static void RegisterUpdatePanel(object sender, EventArgs e)
    {
        try
        {
            MethodInfo m = (from methods in typeof(ScriptManager).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
                            where methods.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")
                            select methods).First<MethodInfo>();
            m.Invoke(ScriptManager.GetCurrent((HttpContext.Current.Handler as Page)), new object[] { sender });
        }
        catch
        {
        }
    }
}

and you can use it like this:
private void createRadWindow()
{
    RadWindow newWnd = DisposableWindowFactory.CreateDisposableWindow();
    RadWindowManager1.Windows.Add(newWnd);
    //manage your controls here
    (newWnd.ContentContainer.FindControl("DisposableUpdatePanel") as UpdatePanel).ContentTemplateContainer.Controls.Add(myControls); 
}


Regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Window
Asked by
DvdBrink
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or