How to trigger validation on first load
Is there a way to trigger the validation on the form on the first load? my form loads its data from the DB and the data could already be partially filled by the user - so i want to run the validation on the first load to show the user what he needs to fill and how much
i failed to mention it earlier - i need to perform the validation on the server side - not client side (all the validators i use have server side validation code as well) - and my attempts to call:
Page.Validate();
Page.Validate("My Validation Group");
both resulted in
Page.IsValid == true;
the full scenario is like this: i have a very long form that stretch over several pages - the user is allowed to move between them and fill in the information - wi开发者_C百科thout validation getting in his way then when he finish he clicks on a different button (that exists on all pages) and that page needs to validate the entire form - and if there is a problem jump the user to where the problem is - i coded all the validation checks into asp.net validation controls - and i whuld like to trigger those controls even if the user jumps to that page by pressing the validate button on a different page - the problem is that the move to that page is regarded as a NEW load of that page (in fact it is - and hence the validation fails to work)
On the load of your page call for the method
Page_ClientValidate();
If you want to call it for a specific validationgroup call it like:
Page_ClientValidate('somevalidationgroupname');
If you want to retrieve the state of the page you can call
Page_IsValid;
Edit:
Frankly it's better to just use CSS to indicate which fields are required to be filled in. My former project used the client side validation approach when someone didn't enter information the first time but went to other parts of the page and on a second time it was opened then it was made clear by client side validation.
Perhaps it's handy to talk with a usability expert on how to best accomplish things before making extra additions to your codebase ending up in decreased user experience.
精彩评论