How To Use LinkLabel Control In ASP.NET Using VB.NET
In this article we demonstrate on what is LinkLabel control,its properties and Events and also on how we can use this control to open a web page.
A visual basic LinkLabel Control is similar to the Label but they shows a Hyperlink. Even multiple Hyperlink can be specified in the Text of the control and each Hyperlink can perform a different task with in the application. They are based on the Label class which is based on the Control class. It is a standard control that lets you embed web-style links in a form. LinkLabel is much more convenient and Trouble free than older techniques. LinkLabel is designed to be used with other object to do the whole job. The basic idea behind the control is to put the e-mail address or web URL in to the Text property of a LinkLabel component then when the Label is Clicked, the Link clicked Event is triggered.
Properties of LinkLabel Control
-
LinkColor:- This property set the color to display a Normal link. Default color is specified by the system is Blue.
-
VisitedLinkColor:- Indicate the color to display a Link that has previously been visited. The default color is specified by the system is purple.
-
Links:- Returns the collection of Links contained within the LinkLabel.
-
ActiveLinkColor:- The color to Display an active Link. Link is active while it is being clicked. The default color is specified by the System is red.
-
DisabledLinkColor:- Shows the color to display Disable Link. Disable Link do not raise the LinkClicked event.
LinkLabel Event
The default Event of the LinkLabel is LinkClicked Event.
Working with LinkLabel control
-
Simply open a new project
-
Drag a LinkLabel, Label control on to the Form. The form will display Like below.
- When you click the LinkLabel. It will take you to VBDOTNETHEAVEN web page. The code for that is given below.
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
Handles LinkLabel1.LinkClicked
System.Diagnostics.Process.Start(www.vbdotnetheaven.com)
'using the start method of system.diagnostics.process class
'process class gives access to local and remote processes
End Sub
- Than you create a LinkLable. The code for creation is given below.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim LinkLabel1 As New LinkLabel()
'LinkLabel1.Text = "click"
LinkLabel1.Location = New Point(135, 70)
LinkLabel1.Size = New Size(30, 20)
Me.Controls.Add(LinkLabel1)
End Sub
Output