<html>
<head>
<title>RequiredFieldValidator Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void greetUser ( object src, EventArgs e ) {
if ( Page.IsValid ) {
message.InnerHtml = "Hello, " + userName.Text +
"<br>Welcome to Web Forms Validation";
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>RequiredFieldValidator Example</span></h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<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."
forecolor="blue" font-bold
runat="server" /></p>
<p id="message" runat="server" />
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>