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

RadWindow and RegisterStartupScript causing multiple windows to open at once

2 Answers 124 Views
Window
This is a migrated thread and some comments may be shown as answers.
Simone
Top achievements
Rank 1
Simone asked on 17 Feb 2012, 04:30 PM
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 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 17 Feb 2012, 05:01 PM
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 >>
0
Simone
Top achievements
Rank 1
answered on 17 Feb 2012, 05:12 PM

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


Tags
Window
Asked by
Simone
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Simone
Top achievements
Rank 1
Share this question
or