I’m having an issue with a standard ASP.NET page that has a TextBox and a RequiredFieldValidator. The steps to reproduce are quite simple:
- Place a TextBox on a page
- Place a RequiredFieldValidator on the page
- Point the RequiredFieldValidator at the TextBox
- Run the app
- Tab away from the TextBox the RequiredFieldValidator does not show
- Enter text, then delete the text and THEN tab away, the RequiredFieldValidator does show
The RequiredFieldValidator works fine in both cases after a postback, however it seems the client-side code isn’t firing until something is entered into the textbox (and then deleted).
Does anyone have a solution to this without hacking away at JavaScript myself?
Is it possible this behavior is by design to suppress the appearance of validation controls until user input?
Generally speaking, Validate() gets called whenever a control is clicked that has CausesValidation set to true, like a submit button.
In any case, a poor mans work around, you could call the page Validate() function from the Load event handler. This will make things clearer to tab happy users that they need to enter something in. E.g.