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.
Code Block
FirstPage.aspx
Add two HyperLink controls.
This is the first page.
<br />
<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink> <br />
<asp:HyperLink ID="HyperLink2" runat="server">HyperLink</asp:HyperLink>

Yes, it is possible to find a good web host. Sometimes it takes a while to find one you are comfortable with. After trying several, we went with Server Intellect and have been very happy thus far. They are by far the most professional, customer service friendly and technically knowledgeable host we’ve found so far.

Step Two

Open SecondPage.aspx in source view. In the open div tags type “This is the second page”.
Code Block
SecondPage.aspx
Type in a message to let the user know this is the second page.
<div>
This is the second page.
</div>

Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!

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.
Code Block
FirstPage.aspx
Change the properties of both HyperLink controls.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="SecondPage.aspx">Second Page</asp:HyperLink>
<br />
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="http://v4.vbasic.net">Visual Basic Tutorials</asp:HyperLink>

I just signed up at Server Intellect and couldn’t be more pleased with my fully scalable & redundant cloud hosting! Check it out and see for yourself.

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’.



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.

thumbnail (2).png