Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 ?

like image 520
Rajbir Singh Avatar asked May 08 '12 06:05

Rajbir Singh


People also ask

How to open new page in new tab in asp net?

open allows you to open a page in new window or tab. Here's a client-side example: $(function () { $('#<%= YourButtonID. ClientID %>').

How to open new tab in vb net?

You just need to use the '_blank' without 'left=100,top=100,resizable=yes' if you want it to open in new tab.

How do I open a new tab on a server?

Default key bindings: F2 create a tab. F3 & F4 you can move around back and forth.


2 Answers

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); } 
like image 98
Arion Avatar answered Oct 06 '22 08:10

Arion


Why not just call window.open straight from OnClick?

<asp:Button ID="btnNewEntry" runat="Server" CssClass="button" Text="New Entry" OnClick="window.open('New.aspx')" /> 
like image 31
James Cahours Avatar answered Oct 06 '22 09:10

James Cahours