MyException - 我的异常网
当前位置:我的异常网» C# » 应验控件为何出错呢

应验控件为何出错呢

www.MyException.Cn  网友分享于:2013-12-18  浏览:3次
验证控件为何出错呢
代码如下,执行到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 "

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有