Rajbir Singh Rajbir Singh - 3 months ago 46
ASP.NET (C#) Question

how to open a page in new tab on button click in asp.net?

I want to open a page in new tab of browser on button click.

I have searched a lot on google but i couldn't find anything.

Here is my button.

<asp:Button ID="btnNewEntry" runat="Server" CssClass="button" Text="New Entry" OnClick="btnNewEntry_Click" />

protected void btnNewEntry_Click(object sender, EventArgs e)
{
Response.Redirect("New.aspx");
}


Can you please help me how i can do this ?

Answer

You could use window.open. Like this:

protected void btnNewEntry_Click(object sender, EventArgs e)
{ 
   Page.ClientScript.RegisterStartupScript(
   this.GetType(),"OpenWindow","window.open('YourURL','_newtab');",true);
}
Comments