I have a user con开发者_开发知识库trol 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 ?
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;
}
And you have the ValidationGroup property set on all the buttons and TextBox's involved to the same validation group name? I've used the validationgroups in a few projects that have fairly deeply neested User controls and custom controls and as long as
ValidationGroup="CommonName" is set on the button being clicked and all the fields involved then the validation shows up properly..
精彩评论