Is there a way to open an asp:HyperLink.NavigateUrl in a new tab and not change location of the current?
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
use <asp:HyperLink Target="_blank" /> actually depending on the users settings that may open a new window.
This works for a new tab in FF and Chrome, doesn’t seem to work in IE (8), but this may depend on the doctype.
Method 2
<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl="http://yoursite.com"
Target="_blank">
This will work.
</asp:HyperLink>
Method 3
<asp:HyperLink ID="lnkCompUrl" runat="server" Width="200px"></asp:HyperLink></li>
lnkCompUrl.Text = Convert.ToString(dsData.Tables[0].Rows[0]["comp_url"]);
string url="http://"+Convert.ToString(dsData.Tables[0].Rows[0]["comp_url"]);
lnkCompUrl.NavigateUrl = String.Format("javascript:void(window.open('"+url+"','_blank'));");
Method 4
protected void grdvEmployeeDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var firstCell = e.Row.Cells[0];
firstCell.Controls.Clear();
firstCell.Controls.Add(new HyperLink { NavigateUrl = String.Format("javascript:void(window.open('" + "EmployeeDetails.aspx?EmpId=" + firstCell.Text + "','_blank'));"), Text = firstCell.Text });
}
}
Method 5
Worked for me:
[asp:HyperLink runat="server" ID="..." Target="_blank" Text=".......".../]
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