的RequiredFieldValidator和preventing的CausesValidation [英] RequiredFieldValidator and 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,他们大多是< DIV>
风格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" />