Default.aspx :-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="container">
<h1>HyperLink Example</h1>
Use list to specify link:<br /><br />
<asp:DropDownList
ID="DropDownList1"
AutoPostBack="True"
runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Select any social site : </asp:ListItem>
<asp:ListItem>facebook</asp:ListItem>
<asp:ListItem>twitter</asp:ListItem>
<asp:ListItem>pinterest</asp:ListItem>
</asp:DropDownList><br /><br />
Here is a link:
<asp:HyperLink ID="hypTest" Runat="server" />
</div>
</form>
</body>
</html>
Default.aspx.cs :-
protected void Page_Load(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 0)
hypTest.Visible = false;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex > 0)
{
string site = DropDownList1.SelectedItem.Text;
hypTest.Visible = true;
hypTest.Text = site;
hypTest.ToolTip = "Go to the web site of " + site;
hypTest.NavigateUrl = "http://www." + site + ".com";
}
}

No comments:
Post a Comment