Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link button property to open in new tab?

Tags:

asp.net

In my application I have some link buttons there but when I right click on them I cannot (they are in disable mode) find the menu items Open in new tab or Open in new window.

How do I show those menu items?

Code example:

<asp:LinkButton id="lbnkVidTtile1" runat="Server" CssClass="bodytext" Text='<%#Eval("newvideotitle") %>'  />
like image 686
Surya sasidhar Avatar asked Apr 14 '10 11:04

Surya sasidhar


People also ask

How do you make a link open in a new tab?

The first method requires a keyboard and a mouse or trackpad. Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.

How do I make a link open in a new tab in HTML?

You can make a HTML link open in a new tab by adding the target=”_blank” attribute. You should insert this after the link address.

How do I open a new tab with CSS?

Add an HTML element to your Page Block: Write your own HTML link / button. It is this attribute (target="_blank") that causes the link to open in a new tab. Everything in the style attribute (style="...") is CSS.

How do I redirect a response in a new tab?

When the Button is clicked, first the SetTarget JavaScript function is called inside which the target property of the Form is set to _blank and after that the Server Side function is executed. Inside the Button Click event handler, the Response. Redirect code is executed and the Page opens in new Tab.


2 Answers

From the docs:

Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.

As this isn't actually performing a link in the standard sense, there's no Target property on the control (the HyperLink control does have a Target) - it's attempting to perform a PostBack to the server from a text link.

Depending on what you are trying to do you could either:

  1. Use a HyperLink control, and set the Target property
  2. Provide a method to the OnClientClick property that opens a new window to the correct place.
  3. In your code that handles the PostBack add some JavaScript to fire on PageLoad that will open a new window correct place.
like image 160
Zhaph - Ben Duguid Avatar answered Oct 15 '22 00:10

Zhaph - Ben Duguid


Here is your Tag.

<asp:LinkButton ID="LinkButton1" runat="server">Open Test Page</asp:LinkButton>

Here is your code on the code behind.

LinkButton1.Attributes.Add("href","../Test.aspx")
LinkButton1.Attributes.Add("target","_blank")

Hope this will be helpful for someone.

Edit To do the same with a link button inside a template field, use the following code.

Use GridView_RowDataBound event to find Link button.

Dim LB as LinkButton = e.Row.FindControl("LinkButton1")         
LB.Attributes.Add("href","../Test.aspx")  
LB.Attributes.Add("target","_blank")
like image 43
Sikandar Amla Avatar answered Oct 15 '22 00:10

Sikandar Amla