Reputation: 447
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
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
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
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
Reputation: 2748
<asp:HyperLink ID="jiraLink" runat="server" Target="_blank">Click Here</asp:HyperLink>
Target="_blank" does the trick for me. Either try:
jiraLink.Target = "_blank";
Also, it looks like you may have left the ending tick mark off (or misplaced) your Text field.
Upvotes: 0