Mega Code Archive

 
Categories / ASP.Net Tutorial / ASP Net Controls
 

HyperLink

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  Inherits="HyperLinkTest" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>HyperLink Test</title> </head> <body>    <form id="form1" runat="server">    <div id="container">       <h1>HyperLink Test</h1>       Use list to specify link:<br/>       <asp:DropDownList ID="drpLinks" Runat="server"           AutoPostBack="True"           OnSelectedIndexChanged="drpLinks_SelectedIndexChanged">                   <asp:ListItem>Select a company</asp:ListItem>         <asp:ListItem>adobe</asp:ListItem>         <asp:ListItem>ibm</asp:ListItem>         <asp:ListItem>microsoft</asp:ListItem>       </asp:DropDownList>       Here is a link:          <asp:HyperLink ID="hypTest" Runat="server" />    </div>    </form> </body> </html> File: Default.aspx.cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class HyperLinkTest : System.Web.UI.Page {   protected void Page_Load(object sender, System.EventArgs e)   {     if (drpLinks.SelectedIndex == 0)       hypTest.Visible = false;   }   protected void drpLinks_SelectedIndexChanged(object sender, System.EventArgs e)   {     if (drpLinks.SelectedIndex > 0)     {       string company = drpLinks.SelectedItem.Text;       hypTest.Visible = true;       hypTest.Text = company;       hypTest.ToolTip = "Go to the web site of " + company;       hypTest.NavigateUrl = "http://www." + company + ".com";     }   } }