我的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.
更多推荐
如何冒泡验证错误的子控件父控件
发布评论