RadWindow and RegisterStartupScript causing multiple windows to open at once

3 posts, 0 answers
  1. Simone
    Simone avatar
    34 posts
    Member since:
    Mar 2011

    Posted 17 Feb 2012 Link to this post

    Hello,
    I am posting a simplified version of my code to demonstrate the problem I am having. 
    If I click on a menu item, one window opens.
    Then, if I click on another menu item, TWO window open. Following clicks cause two windows to open.
    I only want one window to open at a time.
    If I remove ajax, it works fine.

    It seems like Sys.Application.add_load(OpenWindow1) is not being rendered on the page. Not sure why.

    Please help.

    Thanks,
    Simone


           cs:
        protected void Page_Load(object sender, EventArgs e)
        {
        }
     
        protected void subMenu_ItemClick(object sender, RadMenuEventArgs e)
        {
            switch (e.Item.Value)
            {
                case "Window1":
                    {
                        if (!ClientScript.IsStartupScriptRegistered("OpenStartupWindow1"))
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "OpenStartupWindow1", "Sys.Application.add_load(OpenWindow1);", true);
                    }
                    break;
     
                case "Window2":
                    {
                        if (!ClientScript.IsStartupScriptRegistered("OpenStartupWindow2"))
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "OpenStartupWindow2", "Sys.Application.add_load(OpenWindow2);", true);
                    }
                    break;              
            }
        }
    }


    aspx:
    <body>
     
        <div id="div1" runat="server">
            <script type="text/javascript">
                function OpenWindow1() {
                    var oWnd = radopen("WebForm1.aspx", "wndWebForm1");
                }
                function OpenWindow2() {
                    var oWnd = radopen("WebForm2.aspx", "wndWebForm2");
                }
            </script>
        </div>
     
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
     
        <telerik:RadWindowManager ID="RadWindowManagerEmails" ShowContentDuringLoad="false"
            VisibleStatusbar="false" runat="server" EnableShadow="true">
            <Windows>
                <telerik:RadWindow ID="wndWebForm1" runat="server" Behaviors="Close,Move,Resize"
                     Width="1100" Height="600" NavigateUrl="WebForm1.aspx">
                </telerik:RadWindow>
                <telerik:RadWindow ID="wndWebForm2" runat="server" Behaviors="Close,Move,Resize"
                     Width="600" Height="600"
                    NavigateUrl="WebForm2.aspx">
                </telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>
     
            <telerik:RadAjaxManager runat="Server" ID="RadAjaxManager1" >
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="subMenu">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="txt1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
     
        <div style="display: block; width: 100%; height: 30px;">
            <telerik:RadMenu ID="subMenu" runat="server" EnableViewState="false" Orientation="Horizontal"
                SkipLinkText="" CausesValidation="true" OnItemClick="subMenu_ItemClick">
                <Items>
                    <telerik:RadMenuItem Text="Open Window 1" Value="Window1" />
                    <telerik:RadMenuItem Text="Open Window 2" Value="Window2" />
                </Items>
            </telerik:RadMenu>
        </div>
     
        <telerik:RadTextBox ID="txt1" runat="server" Width="400px">
        </telerik:RadTextBox>
        
        </form>
    </body>
  2. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 17 Feb 2012 Link to this post

    Hi Simone,

     The problem comes from the fact that you attach the load handler every time but you never remove it. Would you pease test with the following modification:

    <script type="text/javascript">
     
               function OpenWindow1() {
    Sys.Application.remove_load(OpenWindow1);
                   var oWnd = radopen("WebForm1.aspx", "wndWebForm1");
     
               }
     
               function OpenWindow2() {
     Sys.Application.remove_load(OpenWindow2);
                   var oWnd = radopen("WebForm2.aspx", "wndWebForm2");
     
               }
     
           </script>

    All the best,
    Svetlina Anati
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Simone
    Simone avatar
    34 posts
    Member since:
    Mar 2011

    Posted 17 Feb 2012 Link to this post


    Yes, that was it. Thanks for your quick reply  Svetlina.


Back to Top