Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.net CompareValidator-VCO.DataTypeCheck check other types?

Status
Not open for further replies.

johnfraser

Programmer
Jul 25, 2007
33
US
Hi there. Not new to C# but fairly new to ASP.net C#

I'm working with existing code and needed some explaination:

CompareValidator class and
ValidationCompareOperator.DataTypeCheck

Code:
 public CompareValidator AddDataTypeValidator(WebControl controlToValidate, ValidationDataType dataType, string errorMessage)
        {
            CompareValidator dtv =  new CompareValidator();
            dtv.ID =                GetValidatorName("dtv", controlToValidate);
            dtv.ControlToValidate = GetControlIDForValidator(controlToValidate);
            dtv.ErrorMessage =      errorMessage;
            dtv.Operator =          ValidationCompareOperator.DataTypeCheck;
            dtv.Type =              dataType;
            dtv.Display =           ValidatorDisplay.None;
            AddControl(dtv, controlToValidate);
            return dtv;
        }

========================

Why does this only support the following types?

String = 0,
Integer = 1,
Double = 2,
Date = 3,
Currency = 4,

Finally what would be the best way to support additional validation for other types...? CustomValidator?
 
because that's what asp.net came with.
the best option to add additional datatype checks is to extend the ControlValidator.
Code:
public class MyCompareValidator : ControlValidator
{
}
you'll need to override the validate control property and Evaluate functions. You'll also need to create a new Enum DataType to check the types not validated by the default control.

for more information google "create control validator".

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top