的RequiredFieldValidator和preventing的CausesValidation [英] RequiredFieldValidator and preventing CausesValidation

查看:151
本文介绍了的RequiredFieldValidator和preventing的CausesValidation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有了一个的RequiredFieldValidator 联系人窗体上。

I've got a RequiredFieldValidator on a contact form.

它的工作原理为目的,当人们点击提交,但如果他们点击取消或任何的窗体上的多个菜单时,的的RequiredFieldValidator 取消行动。

It works as intended when people click 'Submit', but if they click 'Cancel' or any of the multiple menus on my form, the RequiredFieldValidator cancels the action.

我已经搜查,发现我需要设置使用的的CausesValidation = (使用后),但我得做我的网页上的每个控件?

I have already searched and found that I need to set the other controls on my form using CausesValidation = False (using this post), but do I have to do that for every control on my page?

是什么使得它更糟糕的是,我的表格上的菜单包含在Master.Page,他们大多是< D​​IV> 风格CSS按钮,但点击任何按钮导致的RequiredFieldValidator 以消防和失败的形式。

What makes it worse is that the menus on my form are contained in a Master.Page, and they are mostly <DIV> style CSS buttons, but clicking any of the buttons causes the RequiredFieldValidator to fire and fail the form.

不应该默认为False,我必须把上控制套验证?

Shouldn't the default be False and I have to turn on which control sets the validation?

推荐答案

您可以设置验证组

             <asp:TextBox ID="tb1" runat="server" ValidationGroup="ValidateMe" />
             <asp:TextBox ID="tb2" runat="server" />
             <asp:RequiredFieldValidator" ID="rfv1" runat="server" ControlToValidate="tb1" ValidationGroup="ValidateMe" />
               ...
             <asp:Button ID="btnSubmit" runat="server" ValidationGroup="ValidateMe" />

从这里

came from here

编辑,对不起,我没把把这个code得当,它并没有显示:

Edit , sorry I didn't put put this in code properly and it didn't display:

或者,你可以随时使用和处理那些在客户端,如果他们只是取消之类的东西。

Or you can always use and handle those on client side if they are just cancel and stuff like that

         <input type="button" > 

这篇关于的RequiredFieldValidator和preventing的CausesValidation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆