具有多个 ValidationGroups 的 Page_ClientValidate() - 如何同时显示多个摘要?
ASP.NET 2.0。假设我有两个验证组 valGrpOne 和 valGrpTwo;以及两个验证摘要 valSummOne 和 valSummTwo;分解部分的原因纯粹是为了美观。一个提交按钮会触发对两组的验证。
现在我想触发客户端验证,并希望同时显示两个验证摘要;
因此,我设置了一个在 btnSubmit 上调用的 Javascript 函数,在该函数内我连续调用 Page_ClientValidate("valGrpOne")
和 Page_ClientValidate("valGrpTwo")
;问题是一次仅显示一个摘要(但我真的希望两者都显示!)
有关如何从客户端代码同时显示两个验证摘要的任何想法?
与以下问题非常相似,该问题针对服务器端进行回答。 使用一个按钮触发多个验证组?
ASP.NET 2.0. Lets say i have two Validation Groups valGrpOne and valGrpTwo; and two Validation Summaries valSummOne and valSummTwo; Reason for breaking up sections is purely aesthetic. One submit button which triggers validation on both groups.
Now i want to trigger Client-Side validation, AND want BOTH validation summaries to display at the same time;
So i setup a Javascript function which gets called upon btnSubmit, and inside this function i call Page_ClientValidate("valGrpOne")
and Page_ClientValidate("valGrpTwo")
in succession; Problem is only one summary shows at a time (But i really want both to show!)
Any ideas on how to get both validation summaries to display simultaneously, from client-side code?
Very similar to the following question, which answers for server-side.
Triggering multiple validation groups with a single button?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好吧,答案并不简单。客户端验证的默认行为似乎是仅显示刚刚验证的最新组/摘要。但一些 Javascript 调整给了我一个可以接受的答案。
请随意提供改进。
Ok, so the answer was not simple. It seems the default behaviour of client-side validation is to show only the lastest group / summary that has just been validated. But a bit of Javascript tweeking gave me an acceptable answer.
Feel free to offer improvements.
这是另一种简单且通用的方法,用于针对多个组进行验证。
Here is another simple and generic method for validating against multiple groups.
未完全测试:
Not fully tested:
为了简单起见,这是一个非常简单的示例:
在页面标题中包含以下 javascript 方法:-
modalPopupExtenderValidations 是模式弹出窗口的 ID。
vgValidations 是验证组的 ID。
现在,在页面预渲染方法中,将 onclick 属性添加到您希望进行验证的按钮。
我希望它很容易理解。
再见。
Here it is to keep it simple, a very simple example:
Have the below javascript method in your Page Header:-
modalPopupExtenderValidations is the ID of the modal popup.
vgValidations is the ID of the Validation Group.
Now, in the page prerender method add the onclick attribute to your button on which you want the validation should occur.
I hope its easy to understand.
Bye.
这是 joedotnot 有用代码的扩展。对于大多数 ASP.NET 用户来说,这可能有点过分了,但这对一个项目很有帮助,该项目必须在提交时应用不同的验证组组合,具体取决于选择的按钮。
然后在各种事件处理程序中:
this is an extension of joedotnot's useful code. It is probably overkill for the majority of asp.net users, but this helped with a project where different combinations of validation groups had to be applied on submit, depending on which buttons had been selected.
then in the various event handlers: