日期:2014-05-19  浏览次数:20794 次

验证控件为何出错呢
代码如下,执行到Page.IsValid时提示出错!!!
<Script   Language= "C# "   Runat= "Server ">
public   void   Page_Load(Object   src,EventArgs   e)
{
if(Page.IsPostBack)
{
if(Page.IsValid)
{
show.Text   =   "已经通过验证 ";
}
else
{
show.Text   =   "没有通过验证 ";
}
}
}
</script>
<html>
<head>
<title> </title>
</head>
<body>
<form   runat= "server ">
<table>
<tr> <td   colspan=2   align= "center "> <b> RequiredFieldValidator控件演示 </b> </td> </tr>
<tr>
<td> 姓名: </td>
<td> <asp:TextBox   id= "name "   runat= "server "   /> *
<asp:RequiredFieldValidator   id= "rfv1 "   runat= "server "
  ControlToValidate= "name "
  Display= "Static "
> (请填写姓名)
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td> <asp:Button     ID=button1   Text= "提交 "   runat= "server "   CausesValidation=true   /> </td>
<td> </td>
</tr>
</table>
<hr>
<asp:Label   id= "show "   ForeColor= "red "   runat= "server "   />
</form>
</body>
</html>

------解决方案--------------------
if(Page.IsValid)
{
show.Text = "已经通过验证 ";
}
else
{
show.Text = "没有通过验证 ";
}
写到BUTTON的CLICK事件中,并设置RequiredFieldValidator的EnableClientScript= "False "