<html>
<head>
<title>Dynamically Setting the Style Properties of a Web Control</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<style>
#greeting {padding:10}
</style>
<script language="C#" runat="server">
void applyStyle ( Object src, EventArgs e ) {
switch ( myStyle.SelectedIndex ) {
case 0:
greeting.Style [ "font" ] ="bold italic 13pt verdana";
break;
case 1:
greeting.Style [ "color" ] ="maroon";
break;
case 2:
greeting.Style [ "background-color" ] ="khaki";
break;
case 3:
greeting.Style [ "border" ] ="1px silver inset";
break;
}
}
void resetStyle ( Object src, EventArgs e ) {
greeting.Style [ "font" ] ="";
greeting.Style [ "color" ] ="";
greeting.Style [ "background-color" ] ="";
greeting.Style [ "border" ] ="";
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Dynamically Setting the Style Properties of a Web Control</h2></div>
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<p><b><asp:label id="greeting" runat="server" text="Greetings, earthling, welcome to ASP.NET." /></b>
<p> </p>
<p>Choose style to apply: <asp:dropdownlist id="myStyle" runat="server">
<asp:listitem text="Font" />
<asp:listitem text="Color" />
<asp:listitem text="BackgroundColor" />
<asp:listitem text="Border" />
</asp:dropdownlist>
<p><input type=submit value="Apply" runat="server"
onServerClick="applyStyle" />
<input type=submit value="Reset" runat="server"
onServerClick="resetStyle" />
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>