On a particular custom list item form I am making for my WSS 3.0 web app, I am required to validate the page when it is loaded up, so that any mistakes the user makes from a previous save are noted immediately. I currently do it by using Page.Validate() in the OnLoad method.

With all of the TextBox and RadioButtonList controls I populate (also on page load), I can simply populate them before I trigger a bunch of InputFormCustomValidator controls on the page. For those controls, everything is clear and the correctly filled out fields are not marked as invalid.

But for the UserField and DateTimeField controls, it will treat them as empty for the page load validation whether or not they have data in them. This occurs both when using the actual UserField and DateTimeField controls that automatically fetch data based on the item ID querystring, and when using the underlying PeopleEditor and DateTimeControl controls which I prepopulate on page load like the text boxes.

Once there's been a post-back that calls for validation, the validation will properly recognize the contents of those fields.

Is there something I can do to get around this, so that correctly filled User and DateTime fields are not marked as invalid on page load? Should I run the validation in a different method than OnLoad? I'd personally like to keep the fields as UserField and DateTimeField rather than using the underlying controls, but that restricts me to not being able to define when they get populated. If the solution is to move the control pre-population to an earlier stage in time, I can settle for that, but it remains preferable not to have to do so if it can be fixed in another way.


Have you tried calling EnsureChildControls() prior to the .Validate()? Also, if you are creating/loading controls dynamically, that is usually done in the CreateChildControls() event rather than the OnLoad() as most custom controls need to participate in the events prior to Load().

  • This did the trick... sorta. Only works if I use the built-in UserField and DateTimeField controls, but it doesn't work with the bare DateTimeControl. Which is curious, but in general unimpactful since I'm preferable to the former in the first place. Thanks, both for the answer and the better tip for common practices. – Grace Note May 26 '11 at 13:30

Perhaps try moving Page.Validate() call to the OnPreRender event?

  • Tried this in conjunction with Dave's answer to see if I could hit the DateTimeControl, but it didn't take. However, switching it to OnPreRenderComplete did successfully hit those, so that seems to do the trick. – Grace Note May 26 '11 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.