How to open asp:HyperLink.NavigationUrl in a new tab

元气小坏坏 提交于 2019-12-29 06:34:06

问题


Is there a way to open an asp:HyperLink.NavigateUrl in a new tab and not change location of the current?


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




回答2:


<asp:HyperLink ID="HyperLink1" 
     runat="server" 
     NavigateUrl="http://yoursite.com" 
     Target="_blank">
       This will work.
</asp:HyperLink>



回答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'));");



回答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 });

    }
}



回答5:


Worked for me:

[asp:HyperLink runat="server" ID="..." Target="_blank" Text=".......".../]


来源:https://stackoverflow.com/questions/1191747/how-to-open-asphyperlink-navigationurl-in-a-new-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!