<html>
<head>
<title>Dynamically Generating Text on a Page</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
string style;
void greetEarthling ( object src, EventArgs e ) {
// get the value entered into the text box and
// assign this as the span control’s content
greeting.InnerHtml = "Greetings, earthling " + userName.Value +
", welcome to ASP.NET.";
// get the value selected from the radio button group
if ( cool.Checked ) style = cool.Value;
else if ( soso.Checked ) style = soso.Value;
else if ( warm.Checked ) style = warm.Value;
// apply the selected style to the span control
greeting.Attributes [ "style" ] = "padding:10; " + style;
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Dynamically Generating Text on a Page</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<p>Please enter your name: <input type=text
id="userName" runat="server">
<p>Choose what suits you: <br>
<input type=radio id="cool" name="cool" runat=server
value="background:navy; color:lime">Cool
<input type=radio id="soso" name="soso" runat=server
value="background:gainsboro; color:dimgray">So-So
<input type=radio id="warm" name="warm" runat=server
value="background:maroon; color:gold">Warm
<p><input type=submit value="Send" runat="server"
onServerClick="greetEarthling">
<p><b><span id="greeting" runat="server" /></b>
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>