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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

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?

Method 3

<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.

Method 4

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x