Search code examples
asp.net.nettextboxcustom-controlscustomvalidator

Server Control creating CustomValidator dynamically


Does anyone have an example of this? I want to create a TextBox inherited control that creates a CustomValidator within it. I don't believe I can create the CustomValidator as a child of the TextBox. I think it needs to be added as a child of the Page itself (I could be wrong).

Any help??

Thanks!


Solution

  • Ok I figured it out. The validator event wasn't being added to the Page.Validators at the right time. I was creating the validator in the CreateChildControls method. This is wrong. It (they) need to be created in the control's Init method so that they are added to the validator stack during the correct time of the page's life cycle. It was simply a move to this Init method and all works fine now.