从孩子的用户控件ASP.Net父用户控制验证 [英] Parent user control validation from child user control ASP.Net

查看:111
本文介绍了从孩子的用户控件ASP.Net父用户控制验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个文本字段,每个分配有requiredfield验证该控件包含其他用户控件包含说这个按钮,我需要验证从父控件文本字段的字段的按钮。对点击的用户控件。

I have a user control which contains two text fields each assigned with requiredfield validators this control contains another user control contains say a button .On click of this button i need to validate the fields from the parent control text fields.

我尝试用Page.IsValid它验证,但显示的错误消息未显示.Error消息仅如果我尝试验证它从包含包含所需字段验证?的Page.Validate(的ValidationGroup)

I try the Page.Validate("ValidationGroup") with Page.IsValid it validates but the error message is not shown .Error message is shown only if i try to validate it from the contains which contains the required field validators ?

在此先感谢

问候,
弗朗西斯P上。

Regards, Francis P.

推荐答案

我遇到了同样的问题,刚才。

I ran into the same issue just now.

我解决它加入我参考了用户控件下方的CustomValidator,并通过公开,需要验证的属性验证从父用户控件。我反正公开这些属性,所以没什么大不了那里。

I solved it by adding a customvalidator beneath my reference to the usercontrol and validated the usercontrol from the parent by exposing the properties that required validation. I was exposing these properties anyway so no big deal there.

<div>
     <uc:MyChildUserControl ID="MyChildUserControl1" runat="server"></uc:MyChildUserControl >
     <asp:CustomValidator ID="MyChildUserControlCustomValidator" runat="server" ValidationGroup="default_validation" ErrorMessage="errormessage to show when the sh*t hit the fan" Text="*"></asp:CustomValidator>
</div>

和则的ServerValidate code:

And then the servervalidate code:

protected void MyChildUserControlCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = MyChildUserControl1.SomeProperty;
}

这篇关于从孩子的用户控件ASP.Net父用户控制验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆