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"><a 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(); |
} |
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
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.
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"
);
}
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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
>
If you should discover any "secrets" to making the "RegisterStartupScript()" process work correctly, I would love to know them!
Lynn
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.
Did you ever find a viable solution for this issue. I'm having the same issue.
thanks
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
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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
);
}
}
}
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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
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
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.
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!
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
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.
Thank's for the reply how to do it in the back code instead, still using Radbutton .
Regards
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.
How I make force the Post-back to close radwindow ?
Thanks
Regards
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
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.
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.
Hi Ahmed,
I would generally advise against such an approach. Please review the following articles on the matter:
- using RadWindow with AJAX and why you should avoid such an update panel, unless absolutely necessary (and why it has the effect of closing the RadWindow): http://docs.telerik.com/devtools/aspnet-ajax/controls/window/how-to/how-to-use-radwindow-with-ajax.
- how to open a RadWIndow from the server code (and, thus, how to close it - just replace the call to show() with close()): http://docs.telerik.com/devtools/aspnet-ajax/controls/window/troubleshooting/opening-from-the-server.
Regards,
Marin BratanovTelerik by Progress