|
Link Button
The LinkButton Web server control is a hyperlink style button control. It looks
like a hyperlink control but is actually a button control with click and command events.
The class hierarchy for this control is as follows:
Object
Control
WebControl
LinkButton
Below is a LinkButton Web server control.
I am a LinkButton
Notable Properties
Below are some notable properties of the LinkButton control.
CausesValidation: Gets/Sets whether the link button performs
validation in other controls
CommandArgument: Gets/Sets an optional argument holding
data about the command specified with CommandName
CommandName: Gets/Sets the command name for this button
Text: Gets/Sets the text displayed in the link button
Sample
Drag a LinkButton and a Label control on to the Web Form. When you click the link
button the label displays some text. The code for that looks like this:
Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles LinkButton1.Click
Label1.Text = "Working with LinkButton"
End Sub
|
HyperLink Control
The HyperLink Web server control is used to create a link to another Web page. The
text in the HyperLink control is specified using the Text property. We can also display
a image on this control instead of text. To display an image we should set the ImageUrl property.
If both the Text and ImageUrl properties are set, the ImageUrl property takes precedence.
If the image is unavailable, the text in the Text property is displayed. The class
hierarchy for this control is as follows:
Object
Control
WebControl
HyperLink
Notable Properties
Below are some notable properties of the Hyperlink control.
ImageUrl: Gets/Sets the image to be displayed in the hyperlink
NavigateUrl: Gets/Sets the URL to navigate to when the hyperlink
is clicked
Target: Gets/Sets the target window or frame to display
the new content when the hyperlink is clicked
Text: Gets/Sets the text in the hyperlink control
Note the target property. You can set the target property to the values displayed
below. The target property allows us to set new page/content to be displayed
in a new browser window, same window, etc. The values are as follows:
_blank: displays the linked content in a new window without frames
_parent: displays the linked content in the immediate frameset parent
_self: displays the linked content in the frame with focus
_top: displays the linked content in the full window without frames
Sample
Drag a hyperlink control on to the form. Select the control and open it's properties
window. From the properties window set the NavigateUrl property to your favorite website
(in the form http://www.xyz.com), Target property to _blank and Text property to some
text. When you run the application and click the hyperlink your favourit website opens
in a new window.
Live Code Demo
LinkButton Sample
Label
LinkButton
Hyperlink Sample
My Favourite Site
|