RadWindows reopens on any other controls click after closing from inside RadWindow

7 posts, 1 answers
  1. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 30 Dec 2014 Link to this post

    I have this RadWindow in a parent page:

    <script type="text/javascript">
     function ShowWindow() {
     var oWnd = window.radopen('Window1.aspx', 'window1');
    }        
    </script>
     
    <body>
      <form id="form1" runat="server">
        <div>
          <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
          </telerik:RadScriptManager>
          <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
              </telerik:RadWindowManager>
    ...........

    This is how I open the RadWindow from code behind of the parent page:
    ...
    else
       {
          Session["fatherMessageID"] = id;
          string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(ShowWindow);</script>";
          ClientScript.RegisterStartupScript(this.GetType(), "showWindow", script);
        }

    This is how I close the RadWindow from inside the RadWindow:
    <script type="text/javascript">
            function GetRadWindow() {
                var oWnd = null;
                if (window.radWindow) oWnd = window.radWindow;
                else if (window.frameElement.radWindow) oWnd = window.frameElement.radWindow;
                return oWnd;
            }
            function CloseWindow() {
                var oWnd = GetRadWindow();
                oWnd.close()
            }
        </script>

    Calling the script from a button inside the RadWindow:
    string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(CloseWindow);</script>";
    ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", script);

    The problem I am experiencing is that the RadWindow after being opened and closed the first time, keeps reopening later on on page load and on click of any controls on the parent page.
    How can I resolve this problem?

    Thanks for supporting
    Felice
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 05 Jan 2015 Link to this post

    Hi Felice,

    To see how to avoid this, I advise that you examine this article: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-opening-from-server.html. It shows how registering a script as a handler to the Sys.Application.Load event needs to be removed from the handlers list as soon as it executes. You can find more details on the matter here: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html.


    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 18 Jan 2015 in reply to Marin Bratanov Link to this post

    Hello Marin,
    I have had a look at the links you gave me but still the problem occurs.
    I need to open a RadWindow from a command button inside a RadTreeView.
    To simplify the example I am using the code given in your links where the window is opened from a button, but still the window opens on post back.
    I would appreciate if you can give me comments on what is missing in this code or a working sample/snippet because I am not coming right here.

    Thanks a lot

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
     
    <!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>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                <Scripts>
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
                </Scripts>
            </telerik:RadScriptManager>
            <script type="text/javascript">
                function openRadWindow() {
                    var radwindow = $find('<%=RadWindow1.ClientID %>');
                    radwindow.show();
                }
            </script>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            </telerik:RadAjaxManager>
            <div>
                <telerik:RadWindow ID="RadWindow1" VisibleOnPageLoad="false" runat="server" Width="450px" Height="450px" NavigateUrl="http://www.telerik.com">
                </telerik:RadWindow>
                <telerik:RadButton ID="RadButton1" runat="server" Text="Open From Server" OnClick="RadButton1_Click">
                </telerik:RadButton>
            </div>
        </form>
    </body>
    </html>

    protected void RadButton1_Click(object sender, EventArgs e)
        {
            string script = "function f(){openRadWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
        }
     
  5. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 19 Jan 2015 Link to this post

    Hello Felice,

    Could you show me what is the button declaration that you are using since I do not see a treeview (or treelist) in the provided sample? I tried your code and thing seem to work fine with me and I am attaching the test page together with a short video with the expected behavior here as a reference so you can confirm if I am missing something.

    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 19 Jan 2015 in reply to Marin Bratanov Link to this post

    Hi Marin,
    thanks for your answer. Actually I have not provided the code with the RadTreeList but a simplified version which represent in any case the problem.
    I have seen the video you sent me, downloaded the project you have attached and tested it.
    It is correct that clicking the button the RadWindow does not reload but on your same project I have reproduced the issue simply reloading the page as you can see in this video.
    So the radwindow reload on a complete page refresh!
    Can you please suggest a solution to avoid this inconvenient?

    Thanks,
    Felice
  7. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 19 Jan 2015 Link to this post

    Hello Felice,

    The behavior I see in the video is entirely expected. When reloading a page that has already been POST-ed, the browser asks you to resend the information and if you confirm/continue, the last postback is initiated again, so the RadButton1_Click method is called again. You can confirm this by placing a breakpoint in it.

    This is a standard browser behavior that cannot be avoided. What you can consider is using AJAX, so there is no full page POST, so the browser will not show that dialog and re-initiate the last postback.

    I am attaching here two videos that demonstrate the expected behavior as a reference.

    You can examine the browser behavior with the following simple code:

    <asp:Button ID="Button1" Text="test postback behavior and reload the page" OnClick="Button1_Click" runat="server" />

    protected void Button1_Click(object sender, EventArgs e)
    {
        //add a breakpoint here so you can see when I am called
    }

    I hope this helps you determine how to proceed with your actual case.

    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  8. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 23 Jan 2015 in reply to Marin Bratanov Link to this post

    Hi Marin,
    thanks for your explanation.
    I solved the problem following this article.

    Best regards
    Felice
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017