按钮和验证器
我有一个带有两个文本框的表。每个文本框都有一个必需的验证器来使用户在文本框中插入数据。
我还有一个登录表来确认用户权限。
当我提交登录按钮时,第一个表中的验证器出现并阻止用户登录。我将登录按钮属性(原因验证)更改为 false,但我在登录表中添加的验证器没有出现。
那么请问我该如何解决这个问题。
I have a Table with two textboxes. Every textbox has a required validator to make the user insert data in the textbox.
I also have a Login table to confirm user privilages.
When I submit the button of login, the validators from the first table appear and prevent the user from logging in. I changed the login button property (Causes validation ) to false, but the validators which I added in the login table didn't appear.
So please how can I solve this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可以通过使用ValidationGroups来解决您的问题。以下是带有较长说明的页面的摘录适合您:
此页面有两组验证者——“Group1”和“Group2”。然后页面上有两个按钮 - 单击“button1”时,将触发第一组验证器。单击“button2”时,将触发第二组验证器。如果验证失败,回发将默认被阻止客户端:
I think you can solve your problem by using ValidationGroups. Here is an excerpt from a page with a longer explanation for you:
This page has two groups – a “Group1” and a “Group2” of validators. There are then two buttons on the page – when button1 is clicked, the first group of validators will fire. When button2 is clicked, the second group of validators will fire. Postback will be blocked client-side by default if the validation fails:
您需要在按钮和验证上使用 ValidationGroup 属性。这允许某些操作在单击按钮时仅在页面上强制执行验证器的子集。
现在当点击btnA时,它只会检查rfvA是否有效(检查txtA),当点击btnB时,它只会检查rfvB是否有效。是的,您可以在同一个验证组中拥有多个验证控件。
当您将 CausesValidation 属性设置为 false 时,您将禁用按钮的所有验证操作,而不仅仅是您不想要的验证操作。
What you need to use is a ValidationGroup attribute on both the buttons and the validations. This allows certain actions to only enforce a subset of validators on the page when the button is clicked.
Now when btnA is clicked, it will only check whether rfvA is valid (checking txtA) and when btnB is clicked, it will only check whether rfvB is valid. And yes you can have multiple validation controls in the same validation group.
When you set the CausesValidation property to false, you were disabling all validation actions for the button, not just the ones you didn't want on.