Take the 2-minute tour ×

I'm fluffing around with validators for some custom CompositeControls at the moment, and in order to get the server-side validation working I need to do the following:

protected override void OnLoad(EventArgs e)

I've not fully grasped the ASP.NET page lifecycle yet, and am wondering if this is a bit of an ASP smell in general, or is it OK?

(The reason I need to call EnsureChildControls() is because my validators are dynamically added in CreateChildControls(), but it seems the server-side validation is performed before CreateChildControls() is naturally called, and hence before I've actually created any validators. So I'm calling EnsureChildControls() to force them to exist.)

share|improve this question
Asp.net is a code smell:) use MVC –  luckyluke Mar 7 '11 at 14:59
Ha, I wish :-) This all has to fit inside SharePoint 2007, which doesn't play so nice with ASP MVC. –  ngm Mar 7 '11 at 15:27

1 Answer 1

Say your routine that adds validators is CrateValidators()

I would suggest you move this to Page_Init and LoadViewState basically

bool _doCreateValidators=false;
void OnPageInit(sender,args){

protected override void LoadViewState(StateBag savedState){
       _doCreateValidators = false;
share|improve this answer

Your Answer


