Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net

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.

like image 765
Omi Avatar asked Oct 25 '25 06:10

Omi


2 Answers

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

like image 132
Tran Anh Hien Avatar answered Oct 26 '25 20:10

Tran Anh Hien


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?

like image 29
Gage Avatar answered Oct 26 '25 20:10

Gage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!