Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a ValidationGroup is valid from code-behind

Is there a method I can call that retrieves a boolean value of whether or not a particular ValidationGroup is valid? I don't want to actually display the validation message or summary - I just want to know whether it is valid or not.

Something like:

Page.IsValid("MyValidationGroup") 
like image 933
Mike Cole Avatar asked Jul 28 '09 19:07

Mike Cole


People also ask

Which sequence must be followed to check whether page validation succeeded?

Validate method is fired automatically by controls that have the CausesValidation property set to true(Which is default value for Button control). Page. IsValid property tells you whether the validation succeeded or not.

Which of the following method validate all controls on page?

If you use the Page. Validate() method on an ASP.NET 2.0 page, validation groups are ignored and all controls are validated.

What is ValidationGroup?

Validation groups allow you to organize validation controls on a page as a set. Each validation group can perform validation independently from other validation groups on the page. You create a validation group by setting the ValidationGroup property to the same name (a string) for all the controls you want to group.


1 Answers

Have you tried using the Page.Validate(string) method? Based on the documentation, it looks like it may be what you want.

Page.Validate("MyValidationGroup"); if (Page.IsValid) {     // your code here. } 

Note that the validators on the control that also caused the postback will also fire. Snip from the MSDN article...

The Validate method validates the specified validation group. After calling the Validate method on a validation group, the IsValid method will return true only if both the specified validation group and the validation group of the control that caused the page to be posted to the server are valid.

like image 189
Scott Ivey Avatar answered Sep 26 '22 07:09

Scott Ivey