HyperLink - ( ASP.NET Web Forms )
Hyperlink control is a common control used in ASP.NET Web Forms. It is used to display a link that redirects the user to another page or location on the web. In this page, we will discuss how to create and use the HyperLink control in ASP.NET Web Forms.
Syntax
Here is the syntax for the HyperLink control:
<asp:HyperLink id="HyperLink1"
runat="server"
NavigateUrl="url"
Text="link text">
</asp:HyperLink>
The NavigateUrl
attribute of HyperLink is used to specify the destination URL, and the Text
attribute is used to specify the text that is displayed for the hyperlink.
Example
Here's an example of using the HyperLink control in ASP.NET Web Forms:
<asp:HyperLink ID="GoogleHyperLink" runat="server" NavigateUrl="http://www.google.com" Text="Visit Google"></asp:HyperLink>
This example creates a HyperLink control that serves as a link to Google's homepage. The NavigateUrl
attribute specifies the destination URL as "http://www.google.com", and the Text
attribute specifies the text that will be displayed as the link.
Output
When the user clicks on the HyperLink control, the browser will navigate to the URL specified in the NavigateUrl
attribute.
Explanation
HyperLink control provides a simple and convenient way to create links that redirect the user to another page or location. It is also possible to add further attributes such as CssClass
, ImageURL
, ToolTip
, etc. to enhance the appearance and functionality of the hyperlink control.
Use
HyperLink is used to create links in web pages that allow the user to navigate to another page or location on the web. It is particularly useful when creating menus, navigation bars, and footers.
Important Points
- The
NavigateUrl
attribute should always be included in the HyperLink control to specify the destination URL. - The
Text
attribute should also be included to specify the text that will be displayed for the hyperlink.
Summary
In this page, we discussed the HyperLink control used in ASP.NET Web Forms. We covered the syntax, example, output, explanation, use, and important points of HyperLink. By including HyperLink in your web pages, you can create links that provide a convenient and simple way for users to navigate to other pages or locations on the web.