Closing telerik:RadWindow on Browser back button

2 posts, 0 answers
  1. SG
    SG avatar
    1 posts
    Member since:
    Dec 2008

    Posted 26 Jun 2013 Link to this post

    I have two forms and a Popup control. These two forms work kinda of like a Wizard. 
    
    On the first form there is a "Next" button which when clicked will bring up a Popup, 
    which when closed will do a doPostback from the client and on the server side it redirects to Form2.
    
    On Form2 Now if you click the Previous button, it does a Postback and I hide the Popup. 
    But if the user clicks the Browser back button, the Popup shows up and I want to hide the Popup.
    
    And when the user closes the Popup it will redirect them to the Form2, which kinda of goes into a loop, 
    So I want to close the Popup when the user clicks on the Browser back button so that they can stay on Form1.
    
    The Browser back button doesn't do a Postback so none of the server side stuff works. 
    I tried to write JS and JQuery on "pageLoad()" it goes into that but all of this fires before the 
    Popup comes up. It just loads it from the cache. Also tried to expire the Cache but I get an empty page. 
    Refresh is not an option for me at this point as there are more than two pages in my flow, and 
    when I refresh it always goes to First page with our architecture. 
    
    Any way to close this pop-up? Your help would be greatly appreciated.
    
    Thanks in advance....
    
    
    
    Form1.aspx
    --------------------------------------------------
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Form1.aspx.cs" Inherits="Popup.Form1" %>
     
    <%@ Register Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register TagPrefix="uc" TagName="Popup" Src="Popup.ascx" %>
    <body>
        <form id="form1" runat="server">
        <div>
            <uc:Popup ID="idPopup" runat="server" />
            <span style="font-size15pxfont-weightbold;">My first form....</span> </br></br>
            Please click on the Next button.... </br></br>
            <asp:Button ID="btnNext" runat="server" Text="Next" OnClick="btnNext_Click" />
        </div>
        </form>
    </body>
    </html> 
    
    Form1.aspx.cs
    
    --------------------------------------------------
    using System;
     
    namespace Popup
    {
        public partial class Form1 : System.Web.UI.Page
        {
            protected override void OnLoad(EventArgs e)
            {
                idPopup.ClosePopup();
            }
     
            protected void btnNext_Click(object sender, EventArgs e)
            {
                idPopup.ShowPopup();
            }
        }
    }
    Form2.aspx
    
    
    -------------------------------------------
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Form2.aspx.cs" Inherits="Popup.Form2" %>
     
    <body>
        <form id="form1" runat="server">
        <div>
            <span style="font-size15pxfont-weightbold;">My second form....</span> </br></br>
            Now if you click the Previous button, it does a Postback and I hide the Popup. But
            if the user clicks the Browser back button, the Popup shows up and I want to hide
            the Popup.
            <br />
            <br />
            And when the user closes the Popup it will redirect them to the Form2. 
    So I want to close the Popup when the user clicks on the Browser back button so 
    that they can stay on Form1</br></br>
            <asp:Button ID="btnPrevious" runat="server" Text="Previous" OnClick="btnPrevious_Click" />         <asp:Button ID="btnNext" runat="server" Text="Next" />     </div>     </form> </body> </html> 
    Form2.aspx.cs
    
    
    -------------------------------------------
    using System;
     
    namespace Popup
    {
        public partial class Form2 : System.Web.UI.Page
        {
            protected void btnPrevious_Click(object sender, EventArgs e)
            {
                Response.Redirect("Form1.aspx");
            }
        }
    }
    Popup.ascx
    
    
    -------------------------------------------
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Popup.ascx.cs" Inherits="Popup.Popup1" %>
    <%@ Register Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <asp:ScriptManager ID="ScriptManager1" runat="server" />   
     
    <asp:Panel runat="server" ID="pnlPopup">
        <telerik:RadWindowManager runat="server" ID="WindowManager" DestroyOnClose="False">
            <Windows>
                <telerik:RadWindow ID="PopupWindow" Modal="true" Behaviors="Move, Close" runat="server" OnClientClose="clientClose">
                    <ContentTemplate>
                       This Popup comes up with some information and when the user closes it, it does 
    a __doPostBack and on the server side it redirects to the Form2.
                    </ContentTemplate>
                </telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>
    </asp:Panel>
     
    <telerik:RadScriptBlock ID="scrAffiliate" runat="server">
        <script type="text/javascript">
     
            //Function helps to potback the form once the pop-up is closed
            function clientClose(sender, args) {
                __doPostBack('__Page''SubmitPopup');
            }
     
            function __doPostBack(eventTarget, eventArgument) {
                if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
                    theForm.__EVENTTARGET.value = eventTarget;
                    theForm.__EVENTARGUMENT.value = eventArgument;
                    theForm.submit();
                }
            }
     
        </script>
    </telerik:RadScriptBlock>
    Popup.ascx.cs
    
    
    -------------------------------------------
    using System;
    using System.Web.UI;
     
    namespace Popup
    {
        public partial class Popup1 : System.Web.UI.UserControl
        {
            public void ShowPopup()
            {
                this.PopupWindow.VisibleOnPageLoad = true;
            }
     
            public void ClosePopup()
            {
                this.PopupWindow.VisibleOnPageLoad = false;
            }
     
            protected override void OnLoad(EventArgs e)
            {
                if (Page.IsPostBack)
                {
                    string eventArg = Request.Form["__EVENTARGUMENT"];
                    if (eventArg == "SubmitPopup")
                    {
                        ClosePopup();
                        Response.Redirect("Form2.aspx");
                    }
                }
            }
        }
    }
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3596 posts

    Posted 28 Jun 2013 Link to this post

    Hello,

    Handling the browser history is not part of the RadControls and is the developer's responsibility. What I can suggest at this point is the following:
    - try opening the popup with a script, registered only when needed, instead of through a server property, as shown in this sticky thread: http://www.telerik.com/community/forums/aspnet-ajax/window/opening-radwindow-from-the-server.aspx.
    - consider using a history.forward() call to disable the back button: http://viralpatel.net/blogs/disable-back-button-browser-javascript/.


    Regards,
    Marin Bratanov
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top