I have followed mutiple examples of Clsoing the Radwindow from the code behind, but nothing seems to be working. I have a couple applications where I have a need to do this but neither will close the radWindow and tehn refresh the existing page. SO in this example, I am exporting to excel and then closing the Radwindow but it never closes.
<
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;
}
// Reload parent page
function refreshParentPage() {
getRadWindow().BrowserWindow.document.location.href = url;
}
Or this one as well
function refreshParentPage() {
getRadWindow().BrowserWindow.location.reload();
}
</
script
>
Here is the code behind, after the export I want the window to close but its a nogo.
protected void lnkExport_Click(object sender, EventArgs e)
{
//Get the Admins that are checked from the dropdown
String checkId = string.Empty;
foreach (RadComboBoxItem checkeditem in cbAdmins.CheckedItems)
{
checkId += checkeditem.Value + ',';
}
checkId = checkId.TrimEnd(' ', ',');
if (checkId == string.Empty)
{
ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "OpenWindow", "alert('Need to pick an Administrator. If none are able to be picked please assign via admin page.');", true);
}
else
{
//Create the Excel File and ready it to be written and shown.
var ExistFile = Server.MapPath("~/Excel/NSS.xlsx");
var File = new FileInfo(ExistFile);
using (ExcelPackage package = new ExcelPackage(File))
{
ExcelWorksheet workSheet = package.Workbook.Worksheets["Sheet1"];
//get all the admins that where Checked but only allow 2
sql = "Select TOP 2 Name, Mail, strFtPhone, strAddress from vw_tblAdmins where intAdminId in (" + checkId + ")";
dt = new DataTable();
dt = c.GetReader(sql);
//1st Row starts on A8 to E8
int rowC = 8;
foreach (DataRow row in dt.Rows)
{
workSheet.Cells["A" + rowC].Value = row[0].ToString();
workSheet.Cells["B" + rowC].Value = "MN-ARNG";
workSheet.Cells["C" + rowC].Value = row[1].ToString();
workSheet.Cells["D" + rowC].Value = row[2].ToString();
workSheet.Cells["E" + rowC].Value = row[3].ToString();
rowC += 1;
}
//Get all the Exportables for the SpreadSheet
sql = "Select Name, Persona, Email, Phone, Address, intRequestId from vw_TokenExport where dtOrdered IS NULL and location = " + cbLocations.SelectedValue;
dt = new DataTable();
dt = c.GetReader(sql);
//1st Row starts on A16 to E16
string requestId = string.Empty;
int user = c.GetUserId();
int rowCount = 16;
foreach (DataRow row in dt.Rows)
{
workSheet.Cells["A" + rowCount].Value = row[0].ToString();
workSheet.Cells["B" + rowCount].Value = row[1].ToString();
workSheet.Cells["C" + rowCount].Value = row[2].ToString();
workSheet.Cells["D" + rowCount].Value = row[3].ToString();
workSheet.Cells["E" + rowCount].Value = row[4].ToString();
requestId += row[5].ToString() + ',';
rowCount += 1;
}
//take of the end Comma
requestId = requestId.TrimEnd(' ', ',');
//Update the table with the dtOrdered and by Whom
sql = "Update tblTokenRequest set dtOrdered = '" + DateTime.Today + "', intOrderedBy = " + user + " where intRequestId in (" + requestId + ")";
c.InsertUpdateDelete(sql);
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=NSSRequest" + DateTime.Today + ".xlsx");
Response.BinaryWrite(package.GetAsByteArray());
Response.Flush();
Response.Close();
Page.ClientScript.RegisterClientScriptBlock(GetType(), "CloseScript", "redirectParentPage('ManageRequests.aspx')", true);
or this one as well
Page.ClientScript.RegisterClientScriptBlock(GetType(),"CloseScript", "refreshParentPage()", true);
}
}
}