I am trying to open a file in new tab on click event of a link button inside gridview using ScriptManager.RegisterStartupScript inside update panel, but its not working. The Code is as below :
filename = Server.UrlEncode(filename);
string js = "<script>window.open('ViewReports.aspx?filename=" + Server.UrlEncode(filename) + "', '_newtab');</script>";
ScriptManager.RegisterStartupScript(UpdatePanel1,UpdatePanel1.GetType(),"Pop up",js,true);
This also not working:
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), js, true);
And when I am using below code outside Update Panel it works:
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(cstype, "dateSrpt", "<script>window.open('ViewReports.aspx?filename=" + Server.UrlEncode(filename) + "', '_newtab');</script>");
There is problem with your inline javascript. It doesn't work with the inline javascript. when I segregated it to the aspx page as separate javascript function and called the function inside the Registerstartupscript, It worked.
Javascript
function OpenPopup() {
window.open('PulseUserManagement.aspx', null, 'height=500, width=1100, status=no, resizable=no, scrollbars=yes, toolbar=no,location=no, menubar=no');
}
CS code
ScriptManager.RegisterStartupScript(updatepanel1, updatepanel1.GetType(), "Pop up", "OpenPopup();", true);
Please try like this, it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With