Home > DeveloperSection > Forums > How to create a link to a website in vb code behind?
lois waisbrooker
lois waisbrooker

Total Post:70

Points:494
Posted on    April-14-2015 12:53 AM

 VB.Net VB Script 
Ratings:


 1 Reply(s)
 485  View(s)
Rate this:

It may be simple but the search words in Google give too many irrelevant results.

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



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    April-14-2015 2:17 AM

Use Response.Redirect if you want to send the current page to a new url:

 

Protected Sub Menu1_MenuItemClick(sender As Object, e As MenuEventArgs) Handles Menu1.MenuItemClick

    If e.Item.Text = "SomeItem" Then

        Response.Redirect("http://www.mindstick.com")

    End If

End Sub

To open a new url in a new window/tab you would have to use javascript. Normally I would recommend just putting the javascript directly onto the aspx page but in the event that the url will use data from the code behind to generate the url you can use the ClientScript.RegisterStartupScript function.

 

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.mindstick.com"

        ClientScript.RegisterStartupScript(Me.GetType(), "script", "window.open('" & sURL + "', 'popup_window');", True)

    End If

End Sub


Modified On Sep-08-2015 04:14:38 AM

Don't want to miss updates? Please click the below button!

Follow MindStick