4

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.

Omi
  • 427
  • 7
  • 21
  • 42
  • 1
    How about HyperLink with QueryString? Then load the data based on QueryString value at next page. – Win Oct 24 '13 at 18:28
  • Since you are using CommandArgument and CommandName I assume you are executing some action when clicking this in the OnRowCommand of your GridView, which means you need a postback. – Hanlet Escaño Oct 24 '13 at 18:31
  • Try looking this post: http://stackoverflow.com/questions/5896143/linkbutton-open-new-window-tab?rq=1 Regards,, Uroš – Uroš Goljat Oct 24 '13 at 18:40
  • @Win: I have used HyperLink, and I know that it will open my page in a new tab.But I want to know what if I use LinkButton. Is there any possible way through which I can open the contents into a new tab.I have also tried opening the content into a new window, and it works. – Omi Oct 25 '13 at 05:07
  • @Hanlet Escaño: Yes I am passing command argument along with command name. But I have used a linkbutton. I tried opening the content into a new window and it does work. But I want to know any possible way to open the same content into a new tab instead of opening into a new window. – Omi Oct 25 '13 at 05:11

4 Answers4

7

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 =))

Tran Anh Hien
  • 687
  • 8
  • 11
1

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?

Community
  • 1
  • 1
Gage
  • 7,365
  • 9
  • 47
  • 77
0
<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.

L_7337
  • 2,650
  • 28
  • 42
  • LinkButton does not have a target, HyperLink does. Check this: http://stackoverflow.com/questions/5896143/linkbutton-open-new-window-tab?rq=1 – L_7337 Oct 24 '13 at 18:53
  • Thanks this worked. Had to add a query string to the URL and this can be done easily in the code behind when using asp Hyperlink control. – Theo Koekemoer Sep 23 '14 at 07:53
0

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.

callisto
  • 4,921
  • 11
  • 51
  • 92