Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

Asp.net control: Using the HyperLink Control

by the3factory 2/29/2008 11:15:00 PM
The HyperLink control enables you to create a link to a page. Unlike the LinkButton control, the HyperLink control does not submit a form to a server.
For example, the page  displays a hyperlink that randomly links to a page in your application.
ShowHyperLink.aspx
<%@ Page Language="VB" %> <%@ Import Namespace="System.IO" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR /xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Sub Page_Load() lnkRandom.NavigateUrl = GetRandomFile() End Sub Function GetRandomFile() As String Dim files As String() = Directory.GetFiles(MapPath(Request.ApplicationPath), "*.aspx") Dim rnd As New Random() Dim rndFile As String = files(rnd.Next(files.Length)) Return Path.GetFileName(rndFile) End Function </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Show HyperLink</title> </head> <body> <form id="form1" runat="server"> <div> <asp:HyperLink id="lnkRandom" Text="Random Link" Runat="server" /> </div> </form> </body> </html>

In the Page_Load event handler in this, a random file name from the current application is assigned to the NavigateUrl property of the HyperLink control.

The HyperLink control supports the following properties (this is not a complete list):

  • Enabled Enables you to disable the hyperlink.

  • ImageUrl Enables you to specify an image for the hyperlink.

  • NavigateUrl Enables you to specify the URL represented by the hyperlink.

  • Target Enables you to open a new window.

  • Text Enables you to label the hyperlink.

Notice that you can specify an image for the HyperLink control by setting the ImageUrl property. If you set both the Text and ImageUrl properties, then the ImageUrl property takes precedence.

Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0