views:

206

answers:

1

Hi ,

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.

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 ?

Thanks in advance

Regards, Francis P.

A: 

I ran into the same issue just now.

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>

And then the servervalidate code:

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