---
title: "How to create a link to a website in vb code behind?"  
description: "How to create a link to a website in vb code behind?"  
author: "Anonymous User"  
published: 2015-04-14  
updated: 2023-07-06  
canonical: https://www.mindstick.com/forum/23095/how-to-create-a-link-to-a-website-in-vb-code-behind  
category: "vb.net"  
tags: ["vb script"]  
reading_time: 2 minutes  

---

# How to create a link to a website in vb code behind?

It may be [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) but the [search](https://www.mindstick.com/articles/65368/best-smo-services-company-in-hyderabad-improve-search-rankings) words in [Google](https://www.mindstick.com/articles/43833/google-lighthouse-and-how-is-it-changing-the-way-we-development-and-design-websites) 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](https://www.mindstick.com/articles/23633/link-builder) goes here

[End](https://yourviews.mindstick.com/view/88503/us-iran-war-live-updates-trump-says-us-in-no-rush-to-end-iran-war) If

End Sub

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that. Here are the steps on how to create a link to website in vb code behind:

1. Create a new Windows Forms project in VB.NET.
2. Add a button control to the form.
3. In the code behind file, add the following code:

VB.Net

```plaintext
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    ' Create a new Hyperlink object.
    Dim hyperlink As New Hyperlink

    ' Set the URL of the hyperlink.
    hyperlink.NavigateUrl = "https://www.google.com"

    ' Set the Text property of the hyperlink.
    hyperlink.Text = "Google"

    ' Add the hyperlink to the form.
    Controls.Add(hyperlink)
End Sub
```

1. Run the project. When you click the button, the hyperlink will be created and the user will be redirected to the Google website.

Here is an explanation of the code:

- The `New` keyword is used to create a new Hyperlink object.
- The `NavigateUrl` property of the Hyperlink object is set to the URL of the website that you want to link to.
- The `Text` property of the Hyperlink object is set to the text that you want to display for the hyperlink.
- The `Controls.Add` method is used to add the hyperlink to the form.

### Reply by Anonymous User

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 IfEnd 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 IfEnd Sub
```


---

Original Source: https://www.mindstick.com/forum/23095/how-to-create-a-link-to-a-website-in-vb-code-behind

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
