如何冒泡验证错误的子控件父控件

编程入门 行业动态 更新时间:2024-10-03 12:29:54
本文介绍了如何冒泡验证错误的子控件父控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的asp页面的网页表单有一个用户控件(控制1 的.ascx)和保存按钮。控制1包含包含几个自定义验证其他用户控制的控制2 的.ascx。

My asp webform page has a user control (Control1.ascx) and a Save button. Control1 contains another user control Control2.ascx that contains several custom validators.

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { if (somecheck1) args.IsValid = false; else args.IsValid = true; } protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args) { if (somecheck2) args.IsValid = false; else args.IsValid = true; }

我不希望Control1.Save code到如果有的话就验证程序的控制2 执行失败。这怎么可能实现呢?我想关于控制2 加入的有效财产和检查,在保存按钮code。这是否合理的做法?还什么应该在有效物业办?

I don’t want Control1.Save code to execute if any of the validators on Control2 fails. How can this be accomplished? I am thinking about adding a Valid property on Control2 and check for that in the Save button code. Does that reasonable approach? Also what should be done in the Valid property?

编辑:感谢您的答复,但我没能上班了这一点。我已经发布更具体的code范例不同的问题在Handling从子控件的验证错误

Thanks for the response but I am not been able to work this out. I have posted a different question with more specific code examples at Handling of validation errors from child controls

推荐答案

做一个 page.validate(customValidator1); 其中customValidator1是你的验证组。然后火了 Page.IsValid(); 如果第一组验证失败,那么Page.IsValid()将返回false。在你的逻辑实现这一点。

Do a page.validate("customValidator1"); where customValidator1 is your validation group. Then fire a Page.IsValid();If the first group validation fails then Page.IsValid() will return false. Implement this in your logic.

更多推荐

如何冒泡验证错误的子控件父控件

本文发布于:2023-11-03 04:27:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554230.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!