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

How to close RadWindow after save?

21 Answers 1401 Views
Window
This is a migrated thread and some comments may be shown as answers.
Wai Loon Ho
Top achievements
Rank 1
Wai Loon Ho asked on 08 Jul 2010, 06:53 AM
Hi All,

I have a link to popup a RadWindow.
This is working fine.

On the popup window, I have 3 radio button (Excel, PDF, CSV) and 2 buttons (Save As, Close).
This is working fine.

When user click on 'Save As' button, system will show a 'Save As' window to user to choose the file name and file location.
System will then export the data to the format they choose.
This is working fine.

When user click on 'Close' button, system will close the popup window.
This is working fine too.

Now, the problem is the popup window didn't close after the data is exported.
I think this is due to the system still need to continue to do the export even I have the close at the end of the function.

Please help.

Parent code.
    <telerik:RadWindowManager ID="reportSettingsWindowManager" KeepInScreenBounds="true" 
        runat="server" VisibleStatusbar="false" DestroyOnClose="true" Modal="true" Behaviors="Close,Move">  
        <Windows> 
            <telerik:RadWindow ID="downloadWindow" DestroyOnClose="true" runat="server" Modal="true" 
                VisibleStatusbar="false" Behaviors="Close,Move" /> 
        </Windows> 
    </telerik:RadWindowManager> 
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
 
        <script language="javascript" type="text/javascript">  
            function fnCustomizeDownload(name) {  
                var radWindowMgr = $find("<%= reportSettingsWindowManager.ClientID %>")  
                var wnd = radWindowMgr.open('<asp:Literal ID="ltrlDownloadFormat" runat="server" />', name);  
                wnd.setSize(300, 225);  
                wnd.show();  
                return false;  
            }  
 
        </script> 
 
    </telerik:RadScriptBlock> 
 
    <div id="content">  
        <ul id="actions">  
            <li id="liDownloadData" runat="server"><href="#" onclick="fnCustomizeDownload('downloadWindow');return false;">  
                <asp:Literal ID="ltrlDownloadData" runat="server" Text="<%$ Resources:Link, ltrlDownloadData %>" /> 
            </a></li>  
        </ul> 
    </div> 
 

Child ASPX Code
    <telerik:RadScriptBlock ID="scriptBlock1" runat="server">  
 
        <script language="javascript" type="text/javascript">  
            function GetRadWindow()  
            {  
                var oWindow = null;  
                if (window.radWindow) oWindow = window.radWindow;  
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;  
                return oWindow;  
            }  
 
    <table style="width: 220px">  
    <tr> 
        <td colspan="2" class="style1">  
        <asp:Panel ID="Panel2" runat="server"  GroupingText="<%$ Resources:ltrlDownloadGroupingText %>" 
                 Height="99px">  
        <asp:RadioButtonList ID="SelRadioButtonList1" runat="server" Height="55px"   
                Width="211px">                  
                <asp:ListItem Selected="True" Text="<%$ Resources:ltrlDownloadExcel %>"></asp:ListItem> 
                <asp:ListItem Text="<%$ Resources:ltrlDownloadPDF %>"></asp:ListItem> 
                <asp:ListItem Text="<%$ Resources:ltrlDownloadCSV %>"></asp:ListItem> 
        </asp:RadioButtonList> 
        </asp:Panel> 
        </td> 
    </tr> 
    <tr> 
        <td> 
            <asp:Button ID="btnSaveAs" runat="server" Text="<%$ Resources:Button, btnSaveAs %>" OnClick="btnSaveAs_Click" /> 
        </td> 
        <td> 
            <asp:Button ID="btnClose" runat="server" Text="<%$ Resources:Button, btnClose %>" OnClick="btnClose_Click" /> 
        </td> 
    </tr> 
    </table>    
 
            function Close()  
            {  
                var arg = new Object();  
                var oWnd = GetRadWindow();  
                oWnd.close(arg);  
            }  
 
        </script> 
 
    </telerik:RadScriptBlock> 
 

Child C# Code
        protected void btnSaveAs_Click(object sender, EventArgs e)  
        {  
            Logger.LogInformation("Start""btnSaveAs_Click""DownloadFormat");  
            DownloadData();  
            lblCloseWindow.Text = GetRadWindowCloseScript();  
            Logger.LogInformation("End""btnSaveAs_Click""DownloadFormat");  
        }  
 
        protected void btnClose_Click(object sender, EventArgs e)  
        {  
            Logger.LogInformation("Start""btnClose_Click""DownloadFormat");  
            lblCloseWindow.Text = GetRadWindowCloseScript();  
            Logger.LogInformation("End""btnClose_Click""DownloadFormat");  
        }  
 
        private void DownloadData()  
        {  
            Logger.LogInformation("Start""DownloadData""DownloadFormat");  
            //CSV  
            if (SelRadioButtonList1.SelectedItem.Text == SelRadioButtonList1.Items[2].Text)  
            {  
                this.SetCSVDelimiter();  
                this.radGrid.MasterTableView.ExportToCSV();  
            }  
            //Excel  
            else if (SelRadioButtonList1.SelectedItem.Text == SelRadioButtonList1.Items[0].Text)  
            {  
                this.radGrid.MasterTableView.ExportToExcel();  
            }  
            //PDF  
            else if (SelRadioButtonList1.SelectedItem.Text == SelRadioButtonList1.Items[1].Text)  
            {  
            }  
            Logger.LogInformation("End""DownloadData""DownloadFormat");  
        }  
 
        public static string GetRadWindowCloseScript()  
        {  
            return @"
            <script type='text/javascript'>
                var oWindow = null; 
                if (window.radWindow) 
                    oWindow = window.radWindow; 
                else if(window.frameElement.radWindow) 
                    oWindow = window.frameElement.radWindow; 
                var currentWindow = oWindow; 
                currentWindow.Close();
            </script>";  
        }  
 

21 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Jul 2010, 12:41 PM
Hello,


Consider the RegisterStartupScript() server method to invoke the client function than injecting the script and see whether it helps. I believe that this blog post will be of help.


-Shinu.
0
Wai Loon Ho
Top achievements
Rank 1
answered on 09 Jul 2010, 03:50 AM
Hi Shinu,
Thanks for the reply.
Actually I tried this method also. It gave me the same result. The RadWindow popup still failed to close by itself.
User still need to click on the 'Close' button to close the popup.
protected void btnSaveAs_Click(object sender, EventArgs e)
{
    Logger.LogInformation("Start", "btnSaveAs_Click", "DownloadFormat");
        DownloadData();
        if (!Page.ClientScript.IsStartupScriptRegistered("CloseWindow"))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", "Close();", true);
        }
    Logger.LogInformation("End", "btnSaveAs_Click", "DownloadFormat");
}
0
Lynn
Top achievements
Rank 2
answered on 21 Aug 2010, 11:28 AM
I have had similar issues when using the RadWindow and attempting to use the RegisterStartupScript() process to close the RadWindow after the processing within the RadWindow is complete.  Googling the Internet produces many recommendations to use the same RegisterStartupScript -- which I have never been able to get to work correctly.

As a workaround, I have since resorted to (from the code behind portion of the RadWindow) performing a Response.Redirect to a "special" .aspx I create for each of these situations...this "special page" contains very little code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="UserIsLoggedOn.aspx.vb" Inherits="UserIsLoggedOn" %>
<!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>
</head>
<body onload="returnToParent();">
    <form id="form1" runat="server">
    <div>
      
    </div>
    </form>
</body>
    <script type="text/javascript">
        function returnToParent() {
            //create the argument that will be returned to the parent page
            var oArg = new Object();
            oArg.selSSO = "Y";
            //get a reference to the current RadWindow
            var oWnd = GetRadWindow();
            //Close the RadWindow and send the argument to the parent page
            oWnd.close(oArg);
        }
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
    </script>
</html>
Please note that there is no "code behind" for the "special page".  If needed, one could also pass data field values to the "special page" via the query string and use them as arguments when returning to the parent.  This method has resolved my issues.  It's not pretty, but it does seem to work predictably for me.

If you should discover any "secrets" to making the "RegisterStartupScript()" process work correctly, I would love to know them!

Lynn
0
Cori
Top achievements
Rank 2
answered on 23 Aug 2010, 02:12 PM
Hello Wai,

I noticed that you have your entire page enclosed in the script tag. Why not try moving your table outside of the script tag and see if that helps.

Also, for Lynn, instead of using RegisterStartupScript, why not just use RegisterClientScriptBlock. It's always worked for me using RegisterClientScriptBlock.

I hope that helps.
0
Justin
Top achievements
Rank 1
answered on 28 Mar 2011, 06:34 PM
Wai,

Did you ever find a viable solution for this issue.  I'm having the same issue.

thanks
0
Svetlina Anati
Telerik team
answered on 31 Mar 2011, 08:49 AM
Hi Justin,

 Basically, what you should do is to execute closing script from the server. If you have tried this but it still does not work, please prepare a sample, fully runnable code (use a fake programmatic datasource of needed) and share the full source code here. Once you provide this, we will built up a test demo and debug and fix it on our side so that you will be then able to apply the same logic in your original application.

Kind regards,
Svetlina
the Telerik team
0
Justin
Top achievements
Rank 1
answered on 31 Mar 2011, 03:12 PM
Here is a simple sample.  This sample uses a radwindow to select export options and used RadGrid for exporting.  Once the grid is exported the window should then be closed.  I cannot get it to close.

default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="Test_Site._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>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
  
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
            <script type="text/javascript">
                function RadContextMenu1_ClientItemClicked(sender, args) {
                    var itemValue = args.get_item().get_value();
                    if (itemValue == "Export") {
                        var dialogPath = '<%= ResolveClientUrl("~") + "exportgrid.aspx" %>';
                        window.radopen(dialogPath, "ExportGridDialog");
                    }
                    return false;
                }
            </script>
        </telerik:RadScriptBlock>
  
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
            <Windows>
                <telerik:RadWindow ID="ExportGridDialog" runat="server" Title="Export Grid" Height="300px" Width="400px" Modal="true" ReloadOnShow="true"
                    ShowContentDuringLoad="false" Behaviors="Move,Close,Reload" VisibleStatusbar="false" ></telerik:RadWindow>
            </Windows>
        </telerik:RadWindowManager>
  
        <telerik:RadContextMenu ID="RadContextMenu1" runat="server" EnableRoundedCorners="true" OnClientItemClicked="RadContextMenu1_ClientItemClicked">
            <Targets>
                <telerik:ContextMenuControlTarget ControlID="rgTest" />
            </Targets>
            <Items>
                <telerik:RadMenuItem Text="Export" Value="Export" />
            </Items>
        </telerik:RadContextMenu>
        Right Click on Grid to view Context Menu
        <telerik:RadGrid runat="server" ID="rgTest" onneeddatasource="rgTest_NeedDataSource">
        </telerik:RadGrid>
    </form>
</body>
</html>

default.aspx.cs
using System;
using System.Data;
  
namespace Test_Site
{
    public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rgTest.DataSource = GenerateTestData();
                rgTest.DataBind();
            }
        }
  
        private DataTable GenerateTestData()
        {
            DataTable testData = new DataTable();
  
            testData.Columns.Add(new DataColumn("Column1"));
            testData.Columns.Add(new DataColumn("Column2"));
            testData.Columns.Add(new DataColumn("Column3"));
            testData.Columns.Add(new DataColumn("Column4"));
            testData.Columns.Add(new DataColumn("Column5"));
  
            for (int i = 0; i <= 10; i++)
                testData.Rows.Add(new object[] { "1", "2", "3", "4", "5" });
  
            return testData;
        }
  
        protected void rgTest_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            rgTest.DataSource = GenerateTestData();
        }
    }
}

exportgrid.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="exportgrid.aspx.cs" Inherits="Test_Site.exportgrid" %>
  
<!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>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
  
        <script type="text/javascript">
            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow;
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                return oWindow;
            }
            function CloseDialog() {
                GetRadWindow().close();
                return false;
            }
        </script>
  
        <div style="height: 21px; margin: 5px; background-color: #747e96; color: white; width: 96%; font-size: 15px; font-weight: bold; padding: 5px;">
            Export Grid Data
        </div>
        <asp:label runat="server" ID="lblErrorMessage" ForeColor="Red"></asp:label>
        <table>
            <tr>
                <td style="vertical-align: top;">
                    File Type:
                </td>
                <td>
                    <asp:RadioButtonList ID="rblFileType" runat="server">
                        <asp:ListItem Text="CSV (Comma Delimited)" Value="CSV" Selected="True" />
                        <asp:ListItem Text="TXT (Tab Delimited)" Value="TXT" />
                        <asp:ListItem Text="XLS (Excel File)" Value="XLS" />
                    </asp:RadioButtonList>
                </td>
            </tr>
            <tr>
                <td>
                    File Name:
                </td>
                <td>
                    <asp:TextBox runat="server" ID="txtFileName" Width="250px"></asp:TextBox>
                    <asp:RequiredFieldValidator runat="server" ID="rfvFileName" ControlToValidate="txtFileName" Text="*" ForeColor="Red" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: right;">
                    <br />
                    <asp:Button runat="server" ID="btnCancel" Text="Cancel" OnClientClick="return CloseDialog();" CausesValidation="false" />
                          
                    <asp:Button runat="server" ID="btnExport" Text="Export" onclick="btnExport_Click" />
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

exportgrid.aspx.cs
using System;
using Telerik.Web.UI;
using System.Data;
  
namespace Test_Site
{
    public partial class exportgrid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
  
        }
  
        protected void btnExport_Click(object sender, EventArgs e)
        {
            switch (rblFileType.SelectedValue.ToUpper())
            {
                case "CSV":
                    ExportToCSV();
                    break;
                case "TXT":
                    ExportToTXT();
                    break;
                case "XLS":
                    ExportToExcel();
                    break;
            }
        }
  
        private void ExportToCSV()
        {
            try
            {
                RadGrid NewRG = new RadGrid();
                  
                NewRG.ID = "rgExportGrid";
                NewRG.DataSource = GenerateTestData();
  
                NewRG.ClientSettings.DataBinding.EnableCaching = true;
                NewRG.ExportSettings.FileName = txtFileName.Text;
                NewRG.ExportSettings.OpenInNewWindow = true;
                NewRG.ExportSettings.Csv.RowDelimiter = GridCsvDelimiter.NewLine;
                NewRG.ExportSettings.Csv.FileExtension = "csv";
                NewRG.ExportSettings.Csv.ColumnDelimiter = GridCsvDelimiter.Comma;
                NewRG.ExportSettings.IgnorePaging = true;
                NewRG.ExportSettings.ExportOnlyData = true;
                NewRG.NeedDataSource += new GridNeedDataSourceEventHandler(ExportGrid_NeedDataSource);
                Page.Controls.Add(NewRG);
                NewRG.DataBind();
  
                NewRG.MasterTableView.ExportToCSV();
                AddCloseScript();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
            }
        }
  
        private void ExportToTXT()
        {
            try
            {
                RadGrid NewRG = new RadGrid();
  
                NewRG.ID = "rgExportGrid";
                NewRG.DataSource = GenerateTestData();
  
                NewRG.ClientSettings.DataBinding.EnableCaching = true;
                NewRG.ExportSettings.FileName = txtFileName.Text;
                NewRG.ExportSettings.OpenInNewWindow = true;
                NewRG.ExportSettings.Csv.RowDelimiter = GridCsvDelimiter.NewLine;
                NewRG.ExportSettings.Csv.FileExtension = "txt";
                NewRG.ExportSettings.Csv.ColumnDelimiter = GridCsvDelimiter.Tab;
                NewRG.ExportSettings.IgnorePaging = true;
                NewRG.ExportSettings.ExportOnlyData = true;
                NewRG.NeedDataSource += new GridNeedDataSourceEventHandler(ExportGrid_NeedDataSource);
                Page.Controls.Add(NewRG);
                NewRG.DataBind();
  
                NewRG.MasterTableView.ExportToCSV();
                AddCloseScript();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
            }
        }
  
        private void ExportToExcel()
        {
            try
            {
                RadGrid NewRG = new RadGrid();
  
                NewRG.ID = "rgExportGrid";
                NewRG.DataSource = GenerateTestData();
  
                NewRG.ClientSettings.DataBinding.EnableCaching = true;
                NewRG.ExportSettings.FileName = txtFileName.Text;
                NewRG.ExportSettings.OpenInNewWindow = true;
                NewRG.ExportSettings.Excel.Format = GridExcelExportFormat.Html;
                NewRG.ExportSettings.IgnorePaging = true;
                NewRG.ExportSettings.ExportOnlyData = true;
                NewRG.NeedDataSource += new GridNeedDataSourceEventHandler(ExportGrid_NeedDataSource);
                Page.Controls.Add(NewRG);
                NewRG.DataBind();
  
                NewRG.MasterTableView.ExportToExcel();
                AddCloseScript();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
            }
        }
  
        protected void ExportGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            RadGrid grid = (RadGrid)sender;
            grid.DataSource = GenerateTestData();
        }
  
        private DataTable GenerateTestData()
        {
            DataTable testData = new DataTable();
  
            testData.Columns.Add(new DataColumn("Column1"));
            testData.Columns.Add(new DataColumn("Column2"));
            testData.Columns.Add(new DataColumn("Column3"));
            testData.Columns.Add(new DataColumn("Column4"));
            testData.Columns.Add(new DataColumn("Column5"));
  
            for (int i = 0; i <= 10; i++)
                testData.Rows.Add(new object[] { "1", "2", "3", "4", "5" });
  
            return testData;
        }
  
        private void AddCloseScript()
        {
            //ClientScript.RegisterStartupScript(typeof(string), "CloseScript", "CloseDialog();", true);
            ClientScript.RegisterStartupScript(typeof(string), "CloseScript", "CloseDialog();", false);
              
        }
    }
}
0
Svetlina Anati
Telerik team
answered on 05 Apr 2011, 01:24 PM
Hello Justin,

 Thank you for the provided code, we were able to reproduce the problem. We researched it and found that the problem is that the response stream is changed to the file and to achieve what you need with this code you should refresh the page.

However, what we suggest is to first close the radWindow (you should do so anyways) and then invoke the export as shown below:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="exportgrid.aspx.cs" Inherits="ContentWindow" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <script type="text/javascript">
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
        function CloseDialog() {
            GetRadWindow().close();
            __doPostBack("<%=btnExport.UniqueID %>", "");
        
    </script>
    <div style="height: 21px; margin: 5px; background-color: #747e96; color: white; width: 96%;
        font-size: 15px; font-weight: bold; padding: 5px;">
        Export Grid Data
    </div>
    <asp:Label runat="server" ID="lblErrorMessage" ForeColor="Red"></asp:Label>
    <table>
        <tr>
            <td style="vertical-align: top;">
                File Type:
            </td>
            <td>
                <asp:RadioButtonList ID="rblFileType" runat="server">
                    <asp:ListItem Text="CSV (Comma Delimited)" Value="CSV" Selected="True" />
                    <asp:ListItem Text="TXT (Tab Delimited)" Value="TXT" />
                    <asp:ListItem Text="XLS (Excel File)" Value="XLS" />
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr>
            <td>
                File Name:
            </td>
            <td>
                <asp:TextBox runat="server" ID="txtFileName" Width="250px"></asp:TextBox>
                <asp:RequiredFieldValidator runat="server" ID="rfvFileName" ControlToValidate="txtFileName"
                    Text="*" ForeColor="Red" />
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: right;">
                <br />
                <asp:Button runat="server" ID="btnCancel" Text="Cancel" OnClientClick="return CloseDialog();"
                    CausesValidation="false" />
                <asp:Button runat="server" ID="btnExport" Text="Export" OnClientClick="CloseDialog();return false;"
                    OnClick="btnExport_Click" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

I hope that my reply is helpful and for your convenience I attached a sample demo - let me know how it goes.


Greetings,
Svetlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chad
Top achievements
Rank 1
answered on 08 Jul 2011, 09:32 PM
Hello Svetlina,

I have the same exact situation and by using your workaround closing the radwindow before doing a postback does nothing but to close the radwindow. It doesnt invoke the export which is defeating the whole purpose. Please let me know if you have any updates or any other workarounds for this situation.

Thanks,
Chad
0
Justin
Top achievements
Rank 1
answered on 11 Jul 2011, 09:09 PM
Chad,

I never found a viable solution to this problem.  I ended up having to leav the window open and requiring the user to close it.

Sorry, I hope you find somwthing that works for ya.
0
Marin Bratanov
Telerik team
answered on 12 Jul 2011, 03:50 PM
Hi guys,

I tried the code provided by Svetlina and I can confirm that it works fine and the RadWindow closes itself. You can find a video from my experiment in the following link: http://screencast.com/t/iMvT5JArfEH. There is only one small omission there - the cancel button calls the same function as the export button, yet this is not related to the other functionality. Please make sure that in your projects the buttons are not wrapped in update panels and the postbacks are executed. If, for some reason the event validation breaks the __doPostBack() function you may try to trigger it by using the client-side name of the button (although this actually does the same as the server code block):
function CloseDialog(button) {
     GetRadWindow().close();
     __doPostBack(button.name, "");
  
<asp:Button runat="server" ID="btnExport" Text="Export" OnClientClick="CloseDialog(this);return false;" OnClick="btnExport_Click" />



Greetings,
Marin
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
vikas
Top achievements
Rank 1
answered on 24 May 2012, 07:20 AM
Dear Telerik,

How about if you use Radbutton instead of button, why won't it work?

function CloseDialog(button) {
     GetRadWindow().close();
     __doPostBack(button.name, "");
}
   
<asp:Button runat="server" ID="btnExport" Text="Export" OnClientClick="CloseDialog(this);return false;" OnClick="btnExport_Click" />

Thank you in advanced
0
Princy
Top achievements
Rank 2
answered on 24 May 2012, 07:48 AM
Hi Vikas,

Try the following code snippet.

ASPX:
<telerik:RadButton runat="server" ID="btnExport" Text="Export" OnClientClicked="CloseDialog" OnClick="btnExport_Click" />

JS:
function CloseDialog(sender,args)
       {
            GetRadWindow().close();
            __doPostBack(sender.name, "");
       }

Thanks,
Princy.
0
vikas
Top achievements
Rank 1
answered on 25 May 2012, 03:36 AM
Dear Princy,

Thank's for the reply how to do it in the back code instead, still using Radbutton .

Regards
0
Princy
Top achievements
Rank 2
answered on 25 May 2012, 07:13 AM
Hi Vikas,

I suppose you want to close the Window from server side. You need to inject the javascript function to the asp label as it's text and write the client side method to close the RadWindow as shown below.

ASPX:
<telerik:RadButton runat="server" ID="btnExport" Text="Export"  OnClick="btnExport_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>

C#:
protected void btnExport_Click(object sender, EventArgs e)
   {
        Label1.Text = "<script type='text/javascript'>CloseDialog()</" + "script>";
   }

JS:
<script type="text/javascript">
    function CloseDialog()
       {
            GetRadWindow().close();
            __doPostBack("<%=btnExport.UniqueID %>", "");
       }
</script>

Hope this helps.

Thanks,
Princy.
0
Christian
Top achievements
Rank 1
answered on 24 Apr 2013, 04:46 PM
I have the same problem . But the difference is that button to download is in Parent Page. then open radwindow and download File.
How I make force the Post-back to close radwindow ?

Thanks

Regards
0
Marin Bratanov
Telerik team
answered on 26 Apr 2013, 01:24 PM
Hello Christian,

If a postback returns as a file it changes the entire response and you cannot register a script that will close the RadWindow.

If you are showing a RadWindow just to download the file and it stays opened without content after that I can suggest you look into the content-disposition HTTP header for your file and send it to the user from the main page without a RadWindow at all. When set to attachment the page will not be disposed because only a file will be returned that will not be inline in the page.


Greetings,
Marin Bratanov
the Telerik team
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 their blog feed now.
0
Amruta
Top achievements
Rank 1
answered on 20 May 2015, 11:21 AM

Hi Marin,

Can you please provide some more details for this?

I need to download a document (display save as option) when user clicks on "Ok" button in a rad window and close the window.

Thanks,

Amruta.

0
Ahmed
Top achievements
Rank 1
answered on 24 Sep 2016, 07:33 PM

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.

0
Marin Bratanov
Telerik team
answered on 26 Sep 2016, 07:16 AM

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.
0
Anatoly
Top achievements
Rank 1
Iron
answered on 09 Mar 2021, 12:18 PM
Good Solution !
Tags
Window
Asked by
Wai Loon Ho
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Wai Loon Ho
Top achievements
Rank 1
Lynn
Top achievements
Rank 2
Cori
Top achievements
Rank 2
Justin
Top achievements
Rank 1
Svetlina Anati
Telerik team
Chad
Top achievements
Rank 1
Marin Bratanov
Telerik team
vikas
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Christian
Top achievements
Rank 1
Amruta
Top achievements
Rank 1
Ahmed
Top achievements
Rank 1
Anatoly
Top achievements
Rank 1
Iron
Share this question
or