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

Open a RadWindow in an async postback?

1 Answer 264 Views
Window
This is a migrated thread and some comments may be shown as answers.
SteveV
Top achievements
Rank 1
SteveV asked on 16 Dec 2011, 12:49 AM
Not sure what I'm doing wrong.  I have an operation (initiated from a GridButtonItem click) that occurs inside an async postback.  Depending on the results of the operation I need to update image and label controls hosted in a RadWindow, display the RadWindow, wait for the user to click a button, determine the button that was clicked and continue with the operation.

For the life of me I can't get the RadWindow to open with generating an exception.  I've stripped out the RadGrid and simplified the code to try to find the problem but alas, no joy.

My aspx looks like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ZZRadWindow.aspx.cs" Inherits="SitefinityWebApp.ZZRadWindow" %>
 
<!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>
    <script>
 
        function OpenWindow()
        {
            var wndMgr = GetRadWindowManager();
            wndMgr.open("", "ConfirmPlaybackWindow");
            return false;
        }
         
    </script>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager runat="server" ID="ScriptMgr" />
        <asp:UpdatePanel ID="WindowUpdatePnl" runat="server">
            <ContentTemplate>
            <asp:Label ID="msgLbl" runat="server" />
                <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false" ReloadOnShow="true" runat="server" Skin="Forest" EnableShadow="true" Font-Bold="False" Modal="True">
                    <Windows>
                        <telerik:RadWindow ID="ConfirmPlaybackWindow" runat="server" DestroyOnClose="False" Skin="Forest" Modal="True">
                            <ContentTemplate>
                                <div class="confirmationDlgWrp">
                                    <div class="alertWrp">
                                        <asp:Image ID="AlertImg" runat="server" CssClass="dlgIcon" />
                                        <asp:Label ID="AlertLbl" runat="server" CssClass="dlgLabel" Text="Hello World" />
                                    </div>
                                    <div class="confirmationDlgBtnWrp">
                                        <asp:Button ID="YesBtn" runat="server" CssClass="dlgYesBtn" Text="Yes" />
                                        <asp:Button ID="NoBtn" runat="server" CssClass="dlgNoBtn" Text="No" />
                                    </div>
                                </div>
                            </ContentTemplate>
                        </telerik:RadWindow>
                    </Windows>
                </telerik:RadWindowManager>
                <asp:Button ID="PostBackButton" runat="server" Text="Do Postback" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <p />
        <asp:Button ID="Button1" runat="server" OnClientClick="return OpenWindow()" Text="Open RadWindow" />
    </div>
    </form>
</body>
</html>

And my codebehind looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace SitefinityWebApp
{
    public partial class ZZRadWindow : System.Web.UI.Page
    {
        private static int PostBackCount = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                msgLbl.Text = string.Format("{0}<p/>PostBackCount: {1}", msgLbl.Text, ++PostBackCount);
                string script2 = "<script type=\"text/javascript\">OpenWindow();</script>";
                ScriptManager.RegisterStartupScript(WindowUpdatePnl, typeof(string), "OpenWindow", script2, false);
            }
        }
    }
}


Clicking the button located outside the UpdatePanel result in the RadWindow displaying without error.  Clicking the postback button located inside the UpdatePanel results in the following exception:

Microsoft JScript runtime error: Sys.InvalidOperationException: Can't be called after dispose

Any idea what I'm doing wrong here?

Thanks -- Steve 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 19 Dec 2011, 09:48 AM
Hi Steve,

Please examine the following article on properly using the RadWindow with AJAX: http://www.telerik.com/help/aspnet-ajax/radwindow-ajaxifying.html. In order to ajaxify the controls from its ContentTemplate you need top lace the update panel inside it. Then you could call its update() method in the code-behind as needed, or simply leave the UpdateMode to conditional. Please note that this scenario (an update panel inside the content template of a RadWindowMAnager) has some limitations related to the general way AJAX and collections work in ASP, which is explained here: http://www.telerik.com/support/kb/aspnet-ajax/window/cannot-unregister-updatepanel-with-id-updatepanelid-since-it-was-not-registered-with-the-scriptmanager.aspx.

I also advise that you examine the following sticky thread on correctly opening the RadWindow from the server: http://www.telerik.com/community/forums/aspnet-ajax/window/opening-radwindow-from-the-server.aspx. There you can find the correct syntax for the RegisterStartupScript() method.


Regards,
Marin
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
SteveV
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or