This tutorial will show you how to use the HyperLink control in Visual Basic.NET. This control is useful for redirecting the user to a web site from a link on a web form. On some web sites you will see blue underlined text that says “Click Here”, and when you click it it will redirect you to another page, that is a HyperLink control in the works. In this tutorial, we will show two examples of the HyperLink control, the first one will redirect to another web form in the project and the second one will redirect to a web site up and running on the internet.

Setting Up

If you have not already done so, open Visual Studio and click File > New > Web Site. Using Visual Basic as the template, select ASP.NET Empty Web Site, name the file HyperLinkControl-VB and click OK. Now right click the web site name and click Add New Item. Once again, using Visual Basic as the template, select Web Form, name the file FirstPage.aspx and click add. Repeat again but name the file SecondPage.aspx.

Step One

Open FirstPage.aspx and switch to source view. Inside the div tags type “This is the first page” and place two HyperLink controls below it.

Step Two

Open SecondPage.aspx in source view. In the open div tags type “This is the second page”.

Step Three

Now we must switch back to FirstPage.aspx and change some of the properties in the HyperLink controls. Click on HyperLink1 and look in the properties window. Insert “SecondPage.aspx” to the ‘NavigateUrl’ property and insert “Second Page” to the ‘Text’ property. Click on HyperLink2 and look in the properties window. Insert “http://v4.vbasic.net” into the ‘NavigateUrl’ property and insert “Visual Basic Tutorials” into the ‘Text’ property.

Output

Run the page and you will see the sentence “This is the first page” along with two HyperLink controls called ‘Second Page’ and ‘Visual Basic Tutorials’.

hyperlink control 1

If you click on the ‘Second Page’ link, it will redirect you to SecondPage.aspx with the message “This is the second page”. If you click on the “Visual Basic Tutorials” link, it will redirect you to our site, v4.vbasic.net.

Thanks for reading and make sure to download the source files to get a better understanding of how the code works.

Download Source Files