Calling JavaScript function from code after Response.End ()
On my page .aspx
, I have div
one that I need to hide using JavaScript after the attachment is loaded. I used the below code to do this. But since it Response
enters the scene, it HideDiv()
does not start.
I even tried to make the div the control server and set the visibility to false
. I also tried to put the part ClientScript
after Response.End();
and inside the block finally
.
try{
ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideDiv()", true);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
Response.Write(tw.ToString());
Response.End();
}
catch (System.Threading.ThreadAbortException)
{
}
catch (Exception ex)
{
//log error
}
finally
{
}
Any idea to get JavaScript to work?
source to share
Create a .aspx
Generic Handler for file upload, then you can call it something like this
ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideDiv()", true);
Response.Redirect("MyHandler.ashx")
OR
Js function to hide div and redirect
function HideDivNRedirect()
{
//hide div
window.location.href='myhandler.ashx';
}
ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideDivNRedirect();", true);
source to share