0

I have an address form WebControl built in a class library that I use in a number of projects within a single solution. I am trying to send in a ValidationGroup and assign it to all the RequiredFieldValidators in that control and it does not work.

Here is the embed on the page...

<supr:SuprAddress ID="iAddress" runat="server" ValidationGroup="frmCheckout" />

I have the public property setup with the WebControl as follows...

private string _validationGroup;
public string ValidationGroup
{
    get
    {
        return _validationGroup;
    }
    set
    {
        _validationGroup = value;
    }
}

NOTE: I have also tried storing this value in ViewState and that did not solve the problem.

And here is a short snippet of the CreateChildControls method...

protected override void CreateChildControls()
{
    txtFirstName = new TextBox() { ID = "txtFirstName", MaxLength = 24 };
    rfvFirstName = new RequiredFieldValidator() { ID = "rfvFirstName", ControlToValidate = txtFirstName.ID, ValidationGroup = this.ValidationGroup };
    // ... add controls, etc...
}

All the control are successfully added and the RequiredFieldValidator is set to validate the textbox, but the validation group is always blank. Any ideas?

CoderMarkus
  • 1,118
  • 1
  • 10
  • 24
  • Put a breakpoint in CreateChildControls. What is the value of `this.ValidationGroup`? – Michael Liu Sep 18 '15 at 20:21
  • I did that and it's null. I'm not sure exactly how the lifecycle executes because the initializer and the CreateChildControls methods both fire when the page loads and the value is null for the ValidationGroup property. At this point I end up calling the CreateChildControls in the OnInit method and everything works. It sucks that the entire CreateChildControls method has to run twice - I guess I will just create like 20 textboxes and them immediately throw them away. – CoderMarkus Sep 18 '15 at 21:00

0 Answers0