Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何在vb代码中创建指向网站的链接?_Asp.net_Vb.net_Url_Code Behind - Fatal编程技术网

Asp.net 如何在vb代码中创建指向网站的链接?

Asp.net 如何在vb代码中创建指向网站的链接?,asp.net,vb.net,url,code-behind,Asp.net,Vb.net,Url,Code Behind,这可能很简单,但谷歌的搜索词给出了太多不相关的结果 Protected Sub Menu1_MenuItemClick(sender As Object, e As MenuEventArgs) Handles Menu1.MenuItemClick If e.Item.Text = "SomeItem" Then 'The link goes here End If End Sub 如果要将当前页面发送到新url,请使用Response.Redirect: Pro

这可能很简单,但谷歌的搜索词给出了太多不相关的结果

Protected Sub Menu1_MenuItemClick(sender As Object, e As MenuEventArgs) Handles Menu1.MenuItemClick
    If e.Item.Text = "SomeItem" Then
      'The link goes here
    End If
End Sub

如果要将当前页面发送到新url,请使用
Response.Redirect

Protected Sub Menu1_MenuItemClick(sender As Object, e As MenuEventArgs) Handles Menu1.MenuItemClick
    If e.Item.Text = "SomeItem" Then
        Response.Redirect("http://www.stackoverflow.com")
    End If
End Sub
要在新窗口/选项卡中打开新url,必须使用javascript。通常我会建议直接将javascript放在aspx页面上,但如果url将使用代码背后的数据生成url,则可以使用
ClientScript.RegisterStartupScript
函数

Protected Sub Menu1_MenuItemClick(sender As Object, e As MenuEventArgs) Handles Menu1.MenuItemClick
    If e.Item.Text = "SomeItem" Then
        Dim sURL As String = "http://www.stackoverflow.com"
        ClientScript.RegisterStartupScript(Me.GetType(), "script", "window.open('" & sURL + "', 'popup_window');", True)
    End If
End Sub

Response.Redirect(“http://www.stackoverflow.com“”
据我所知,如果不使用
ClientScript.RegisterStartupScript
生成要在客户端上运行的javascript代码,就无法在代码隐藏中打开新选项卡。好的,这个答案很有用