<html>
<head>
<title>Handling Control Action Events</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void greetUser ( Object src, EventArgs e ) {
message.Text = Page.IsValid ? "Greetings, " + userName.Text +
"<br>Welcome to the world of ASP.NET " +
"<img src='/shared/biggrin.gif' width=15 height=15 border=0 alt=''>" : "";
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Handling <span class="hilite">Control</span> Action <span class="hilite">Events</span></h2></div>
<hr size=1 width=92%>
<form runat="server">
<div align="center">
<p>Enter your name: <asp:textbox id="userName" runat="server" />
<asp:button text="Enter" onClick="greetUser" runat="server" />
<p><asp:requiredfieldvalidator
controltovalidate="userName"
display="dynamic"
errormessage="Sorry, but I need to know your name.
<img src='/shared/razz.gif' width=15 height=15 border=0 alt=''>"
forecolor="blue" font-bold
runat="server" /></p>
<asp:label id="message" runat="server" />
</div>
</form>
<% if ( IsPostBack ) { %>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
<% } %>
</body>
</html>