Omi
Omi

Reputation: 447

How to use a Linkbutton to open into a new tab?

I am using a linkbutton within a gridview control.I want to open the data into a new tab.I tried to set target="_blank". But it is not working. I have tried doing this.This is my source code:

<asp:LinkButton ID="LinkButton1" runat="server"
            CommandArgument="<%# Container.DataItemIndex %>" CommandName="###"
            Font-Underline="False" Text='<%# Eval("###") target="_blank" %>' />

Please guide me and give me suggestions where I am doing wrong.

Upvotes: 4

Views: 33206

Answers (4)

Tran Anh Hien
Tran Anh Hien

Reputation: 757

Page_Load use:

 btnSubmit.Attributes.Add("href", "https://google.com/");
 btnSubmit.Attributes.Add("target", "_blank");

Or use javascript:

 <asp:LinkButton id="lnkTitle" runat="server" OnClientClick="return NewWindow();" OnClick="lnkTitle_Click" > Open Window</asp:LinkButton>    

<script type="text/javascript">
function NewWindow() {
    document.forms[0].target = '_blank';
}
</script>

Good successs =))

Upvotes: 7

callisto
callisto

Reputation: 5083

If you use

OnClientClick="window.open('/folder/Report.aspx'); 

in your LinkButton it opens in a new tab, but it does so on left click. Right click and selecting open in new tab will also open in new tab.

With with Linkbutton the user cannot control the target.

Upvotes: 0

Gage
Gage

Reputation: 7513

At most you can make it open into a new window and depending on the users internet settings it will open in a new tab. There's no way to make it open in a new tab though.

http://www.webmaster-talk.com/html-forum/32504-hyperlink-target-open-in-new-tab.html

Also check out this page:

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

Upvotes: 1

L_7337
L_7337

Reputation: 2748

<asp:HyperLink ID="jiraLink" runat="server" Target="_blank">Click Here</asp:HyperLink>

Target="_blank" does the trick for me. Either try:

  1. Capital "T" for target
  2. Or, in the code behind, try:

jiraLink.Target = "_blank";

Also, it looks like you may have left the ending tick mark off (or misplaced) your Text field.

Upvotes: 0

Related Questions