Closing radwindow after server side code has executed within RadWindow.

10 posts, 0 answers
  1. Greg
    Greg avatar
    8 posts
    Member since:
    Sep 2011

    Posted 03 Nov 2011 Link to this post

    I have a button that opens a RadWidow that has it's NavigateUrl set to another .Net page in my project.

    Basically the loaded page has a user fill in a form and click on a submit button that does some code behind processing and submission. I would then like to have the RadWindow automaticall close after submission. How could I do this?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Nov 2011 Link to this post

    Hello Greg,

    You can try the following code snippet.

    C#:
    protected void Button1_Click(object sender, EventArgs e)
    {
      //server code
      ScriptManager.RegisterStartupScript(this, GetType(), "close", "CloseModal();", true);
    }

    JS:
    <script type="text/javascript">
    function GetRadWindow()
     {
       var oWindow = null;
       if (window.radWindow)
        oWindow = window.radWindow;
       else if (window.frameElement && window.frameElement.radWindow)
        oWindow = window.frameElement.radWindow;
       return oWindow;
     }
    function CloseModal()
     {
      // GetRadWindow().close();
      setTimeout(function ()
      {
           GetRadWindow().close();
      }, 0);
     }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tim Barton
    Tim Barton avatar
    30 posts
    Member since:
    Apr 2003

    Posted 13 Dec 2011 Link to this post

    Hi,

    If you have RadAjaxManager on your page you can call the following:

    RadAjaxManager1.ResponseScripts.Add("CloseModal();") 


    A little bit less typing :)

    Tim
  5. Joel R
    Joel R avatar
    25 posts
    Member since:
    Nov 2007

    Posted 09 Jan 2014 Link to this post

    In trying the above I get the following error in IE 11 but not Chrome.  The error occurs right after the modal window is closed. 

    Unhandled exception at line 324, column 25 in http://localhost:51522/LocationNew.aspx?rwndrnd=0.8602546546901856

    0x800a138f - JavaScript runtime error: Unable to get property 'Application' of undefined or null reference




    A snippet from the debuger
    CloseModal();Sys.Application.initialize();

    telerik version 2012.3.1016.35


    Any thoughts would be appreciated.
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Jan 2014 Link to this post

    Hi,

    Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadWindow runat="server" ID="RadWindow1">
        <ContentTemplate>
            <telerik:RadButton ID="RadButton1" runat="server" Text="CloseWindow" OnClick="RadButton1_Click">
            </telerik:RadButton>
        </ContentTemplate>
    </telerik:RadWindow>
    <asp:Button ID="Button1" Text="show the RadWindow" runat="server" OnClientClick="showWin(); return false;" />

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, GetType(), "close", "CloseModal();", true);
    }

    JavaScript:
    <script type="text/javascript">
        function showWin() {
            $find("RadWindow1").show();
        }
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement && window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow;
        }
        function CloseModal() {
            var oWnd = GetRadWindow();
            if (oWnd) oWnd.close();
        }
    </script>

    Let me know if you have any concern.
    Thanks,
    Princy,
  7. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 10 Jan 2014 Link to this post

    Hello guys,

    You can also try adding a small timeout around close:
    function CloseModal() {
        var oWnd = GetRadWindow();
        if (oWnd) setTimeout(function(){oWnd.close();}, 0);
    }

    You can also consider using the Sys.Application.Load event to register the script to let the page finish processing before closing it. This may be needed if DestoryOnClose is set to true so that it disposes. If it is not needed you can set it to false which is likely to alleviate the issue.

    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.
  8. Joel R
    Joel R avatar
    25 posts
    Member since:
    Nov 2007

    Posted 10 Jan 2014 Link to this post

    perfect.... Thanks Marin
  9. Ahmed
    Ahmed avatar
    3 posts
    Member since:
    Jul 2015

    Posted 24 Sep in reply to Greg Link to this post

    Simple way to force closing rad window, just put it inside update panel like that :
    <asp:UpdatePanel ID="uppChangeHallPriceWindow" runat="server" UpdateMode="Conditional" RenderMode="Block">
      <ContentTemplate>
         <telerik:RadWindow ID="RadWindow1" runat="server">
           <ContentTemplate>
                                            
           </ContentTemplate>
        </telerik:RadWindow>
      </ContentTemplate>
    </asp:UpdatePanel>
    Important: you have to apply this properties to the update panel :
     UpdateMode="Conditional" RenderMode="Block"

    then inside the button you want to execute the close command perform :
    updatepanel1.update()
    this command will close radwindow and no refresh to your Webpage and no need to javascript, I tried it.
  10. Ahmed
    Ahmed avatar
    3 posts
    Member since:
    Jul 2015

    Posted 24 Sep in reply to Greg Link to this post

    Simple way to force closing rad window, just put it inside update panel like that :
    <asp:UpdatePanel ID="uppChangeHallPriceWindow" runat="server" UpdateMode="Conditional" RenderMode="Block">
      <ContentTemplate>
         <telerik:RadWindow ID="RadWindow1" runat="server">
           <ContentTemplate>
                                            
           </ContentTemplate>
        </telerik:RadWindow>
      </ContentTemplate>
    </asp:UpdatePanel>
    Important: you have to apply this properties to the update panel :
     UpdateMode="Conditional" RenderMode="Block"

    then inside the button you want to execute the close command perform :
    updatepanel1.update()
    this command will close radwindow and no refresh to your Webpage and no need to javascript, I tried it.
  11. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 26 Sep Link to this post

    Hi Ahmed,

    I would generally advise against such an approach. Please review the following articles on the matter:


    Regards,
    Marin Bratanov
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017