首页上一页 1 下一页尾页 1 条记录 1/1页
关于5.15小节ValidationSummary控件应用的问题
发表在ASP.NET图书答疑
2008-03-23
是否精华
是
否
版块置顶:
是
否
<P>我的Default.aspx内容如下:</P>
<P><body><BR> <form id="form1" runat="server"><BR> <div><BR> 用户名:<asp:TextBox ID="TextBox1" runat="server" TextMode="SingleLine"></asp:TextBox><BR> <asp:RequiredFieldValidator ID="RequiredFiledValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator><BR> <br /><BR> 昵称:<asp:TextBox ID="TextBox2" runat="server" TextMode="SingleLine"></asp:TextBox><BR> <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox2" ErrorMessage="昵称巳存在" OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator><BR> <br /><BR> 密码:<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox><br /><BR> 再输入一次密码:<asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox><BR> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox3" ControlToValidate="TextBox4" ErrorMessage="两次输入的密码不一致"></asp:CompareValidator><BR> <br /><BR> E-mail:<asp:TextBox ID="TextBox5" runat="server" TextMode="SingleLine"></asp:TextBox><BR> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" <BR> ControlToValidate="TextBox5" ErrorMessage="输入的邮箱不正确" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator><BR> <br /><BR> 年龄:<asp:TextBox ID="TextBox6" runat="server" TextMode="SingleLine"></asp:TextBox><BR> <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox6" ErrorMessage="输入的年龄不正确"<BR> MinimumValue="5" MaximumValue="100" Type="Integer"></asp:RangeValidator><BR> <br /><BR> <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" DisplayMode="List" /><BR> <asp:Button ID="Button1" runat="server" Text="确定" /><BR> </div><BR> </form><BR></body></P>
<P>Default.aspx.cs内容如下:</P>
<P>public partial class _Default : System.Web.UI.Page <BR>{<BR> protected void Page_Load(object sender, EventArgs e)<BR> {</P>
<P> }<BR> protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)<BR> {<BR> if (args.Value == "mr")<BR> {<BR> args.IsValid = false;<BR> }<BR> else args.IsValid = true;<BR> }<BR>}</P>
<P>运行能正常生成网页,但昵称的控件验证怎么都不执行,其它的控件执行都很正常,我把昵称控件复制出来单独放在一个网页中也能正常执行.<BR>麻烦帮我看一下,谢谢!</P>
<P><body><BR> <form id="form1" runat="server"><BR> <div><BR> 用户名:<asp:TextBox ID="TextBox1" runat="server" TextMode="SingleLine"></asp:TextBox><BR> <asp:RequiredFieldValidator ID="RequiredFiledValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator><BR> <br /><BR> 昵称:<asp:TextBox ID="TextBox2" runat="server" TextMode="SingleLine"></asp:TextBox><BR> <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox2" ErrorMessage="昵称巳存在" OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator><BR> <br /><BR> 密码:<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox><br /><BR> 再输入一次密码:<asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox><BR> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox3" ControlToValidate="TextBox4" ErrorMessage="两次输入的密码不一致"></asp:CompareValidator><BR> <br /><BR> E-mail:<asp:TextBox ID="TextBox5" runat="server" TextMode="SingleLine"></asp:TextBox><BR> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" <BR> ControlToValidate="TextBox5" ErrorMessage="输入的邮箱不正确" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator><BR> <br /><BR> 年龄:<asp:TextBox ID="TextBox6" runat="server" TextMode="SingleLine"></asp:TextBox><BR> <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TextBox6" ErrorMessage="输入的年龄不正确"<BR> MinimumValue="5" MaximumValue="100" Type="Integer"></asp:RangeValidator><BR> <br /><BR> <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" DisplayMode="List" /><BR> <asp:Button ID="Button1" runat="server" Text="确定" /><BR> </div><BR> </form><BR></body></P>
<P>Default.aspx.cs内容如下:</P>
<P>public partial class _Default : System.Web.UI.Page <BR>{<BR> protected void Page_Load(object sender, EventArgs e)<BR> {</P>
<P> }<BR> protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)<BR> {<BR> if (args.Value == "mr")<BR> {<BR> args.IsValid = false;<BR> }<BR> else args.IsValid = true;<BR> }<BR>}</P>
<P>运行能正常生成网页,但昵称的控件验证怎么都不执行,其它的控件执行都很正常,我把昵称控件复制出来单独放在一个网页中也能正常执行.<BR>麻烦帮我看一下,谢谢!</P>