Validation Groups

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?
 
B

bruce barker

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)
 
G

Guest

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...
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top