<% @ page language="c#" %>
<script language="c#" runat="server">
public void page_load(Object src,EventArgs e){
if(Page.IsPostBack){
if(Page.IsValid){
show.Text="<font color=green>通过</font>";
}
else{
show.Text="<font color=red>验证错误</font>";
}
}
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<form runat="server">
<table>
<tr>
<td>姓名</td>
<td>
<asp:TextBox id="name"  runat="server" /><br>
<asp:RequiredFieldValidator id="rfv1" runat="server"
ControlToValidator="name"
Display="static"
ErrorMessage=" name forbbiden"
>(请填写姓名)
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>年龄</td>
<td>
<asp:TextBox id="age"  runat="server" /><br>
<asp:RequiredFieldValidator id="rfv2" runat="server"
ControlToValidator="age"
Display="static"
ErrorMessage="age forbbiden"
>(请填写年龄)
</asp:RequiredFieldValidator></td>
</tr>
<tr><td colspan=2><asp:Button Text="确定" runat="server" /></td></tr>
</table>
<asp:Label id="show" runat="server" />
</form>
</body>
</html>
=========================================
错误
===========================================
Server Error in '/nns' Application.
--------------------------------------------------------------------------------The ControlToValidate property of 'rfv1' cannot be blank. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: The ControlToValidate property of 'rfv1' cannot be blank.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  Stack Trace: 
[HttpException (0x80004005): The ControlToValidate property of 'rfv1' cannot be blank.]
   System.Web.UI.WebControls.BaseValidator.ControlPropertiesValid() +1699126
   System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +28
   System.Web.UI.Control.PreRenderRecursiveInternal() +71
   System.Web.UI.Control.PreRenderRecursiveInternal() +156
   System.Web.UI.Control.PreRenderRecursiveInternal() +156
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5448