Here I am going to explain how to open new tab/window on Button click using asp.net.
A week ago, i have to implement that code. I have option to use java-script windows.open to open new tab.
But I have to insert or update some database entry. Yeah i know that there is another way to use client-script in code behind to achieve this.
But in its simplest form, following code open new tab/window.
<asp:Button ID=”btnNewEntry” runat=”Server” CssClass=”button” Text=”New Entry” OnClick=”btnNewEntry_Click” OnClientClick=”aspnetForm.target =’_blank’;”/>
<%– aspnetForm.target =’_blank’ will add handler to open new tab–%>
protected void btnNewEntry_Click(object sender, EventArgs e)
{
Response.Redirect(”New.aspx”);
}
OR
Response.Write( “<script> window.open( ‘pageName.aspx’ ); </script>”);
Response.End();
No working
protected void btnNewEntry_Click(object sender, EventArgs e)
{
Response.Redirect(”New.aspx”);
}