Validation Groups

  • Thread starter Thread starter Joey
  • Start date Start date
J

Joey

asp.net 2/C#/VS2005

Using master pages

I have a page with several text boxes on it. I want to logically group
some of them. So I have a textbox that has required field and regular
expression validators for it. I also have a validation summary on the
page. For each of these four controls, I used the same value for the
"ValidationGroup" property. I have also assigned header text for the
validation summary and error messages for the validators.

But when I run the page, don't enter anything into the text box, and
click an image button (to trigger a postback), nothing happens. No
error message shows.

Is there something else I need to do to make this work?
 
for each postback control, you specify causesvalidation, and the
validation group if you want it to perform validation. this allows
different buttons to cause different validation or non.

-- bruce (sqlwork.com)
 
Howdy,

I don't know why but it's by design (snippet from RegularExressionValidator):

protected override bool EvaluateIsValid()
{
string input = base.GetControlValidationValue(base.ControlToValidate);
if ((input == null) || (input.Trim().Length == 0))
{
return true;
}
try
{
Match match = Regex.Match(input, this.ValidationExpression);
return ((match.Success && (match.Index == 0)) && (match.Length ==
input.Length));
}
catch
{
return true;
}
}

IMHO it looks like a big simplification (or 'screw up' would be more
convenient) from MST...
 
Howdy,

I actually missed one thing in the documentation:
"Note Validation succeeds if the input control is empty. If a value is
required for the associated input control, use a RequiredFieldValidator
control in addition to the RegularExpressionValidator control. ". So you
have to add RequiredFieldValidator for the same control.

Regards
 
Back
Top