What you want to do is use the ScriptManager
to make the JavaScript call.
The JavaScript snippet you had defined works, however, you need the ScriptManager
to take care of executing it for you.
String js = "window.open('Signature.aspx', '_blank');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Open Signature.aspx", js, true);
The issue with using Response.Write
is that during PostBack
, the browser will not execute script tags. On the other hand, when using ScriptManager.RegisterClientScriptBlock
, the ASP.NET ScriptManager
will execute the code automatically.
UPDATE - 2013/02/14
As suggested in Vladislav's answer, use ClientScript
vs. ScriptManager
; the difference is ClientScript
is for synchronous postbacks only (no asp:UpdatePanel
), and ScriptManager
is for asynchronous postbacks (using asp:UpdatePanel
).
Additionally, per the author's comment below - enclosing the asp:GridView
in an asp:UpdatePanel
will eliminate the browser message confirming a refresh. When refreshing a page after a synchronous postback (no asp:UpdatePanel
), the browser will resend the last command, causing the server to execute the same process once more.
Finally, when using an asp:UpdatePanel
in conjunction with ScriptManager.RegisterClientScriptBlock
, make sure you update the first and second parameters to be the asp:UpdatePanel
object.
ScriptManager.RegisterClientScriptBlock(updatePanel1, updatePanel1.GetType(), "Open Signature.aspx", js, true);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…