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

后端 未结 5 2052
野性不改
野性不改 2020-12-17 08:12

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

相关标签:
5条回答
  • 2020-12-17 08:18
    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 });
    
        }
    }
    
    0 讨论(0)
  • 2020-12-17 08:19
    <asp:HyperLink ID="HyperLink1" 
         runat="server" 
         NavigateUrl="http://yoursite.com" 
         Target="_blank">
           This will work.
    </asp:HyperLink>
    
    0 讨论(0)
  • 2020-12-17 08:31

    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.

    0 讨论(0)
  • 2020-12-17 08:32

    Worked for me:

    [asp:HyperLink runat="server" ID="..." Target="_blank" Text=".......".../]
    
    0 讨论(0)
  • 2020-12-17 08:34
    <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'));");
    
    0 讨论(0)
提交回复
热议问题