验证控件为何出错呢

长春利群 2007-07-22 04:28:19
代码如下,执行到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>
...全文
122 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
长春利群 2007-07-23
  • 打赏
  • 举报
回复
哦,有点明白了。是不是在客户端验证不能使用Page.IsValid属性了?
freeboy827 2007-07-23
  • 打赏
  • 举报
回复
if(Page.IsValid)
{
show.Text = "已经通过验证";
}
else
{
show.Text = "没有通过验证";
}
写到BUTTON的CLICK事件中,并设置RequiredFieldValidator的EnableClientScript="False"

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧