Creating A Designer Enabled Custom Validator Control Pt. I
page 2 of 5
by King & Keith Wells
Feedback
Average Rating: 
Views (Total / Last 10 Days): 25432/ 87

Server-Side Validation Page 2

Page 2

           [

            DefaultProperty("Text"),

            ToolboxData("<{0}:DualValidator runat=server></{0}:DualValidator>")

            ]

   Defining Validator

 The base class used for this control is the BaseValidator class. By inheriting from the BaseValidator class, you will have access to all of its properties and methods.
Some of the methods that you will have to override in this example are EvaluateIsValid
and the ControlPropertiesValid method.
The EvaluateIsValid is used to determine if the value being evaluated is valid or not. The ControlPropertiesValid method is used to determine whether the control defined in the ControlToValidate property is validatable.

            public class DualValidator : BaseValidator

            {
             
          string strFunctionName ;
                        public DualValidator() :base()

                        {           //

                                    // TODO: Add constructor logic here

                                    //                }

                           

TypeConverter

Shows the value of a property as text to the property browser. Also converts the text value to an object. 

ValidatedControlConverter

Converts the control to a string and shows the value to the designer as a control that can be validated by a validation control.

You can see in the dropdownlist below, a list of controls that can be validated by the validation control.

 

 

 

FIGURE 1

CategoryAttribute

This attribute defines where in the visual designer your property or event will appear. You can see in Figure 1 above that the PrimaryControl, FirstControlToValidate and the SecondControlToValidate are defined under the BEHAVIOR category group.                                                     

 CREATING NEW CONTROL PROPERTIES

 I have defined three new properties whose values can be set visually in the properties window of the designer. These three custom properties,the PrimaryControl, FirstControlToValidate and SecondControlToValidate will allow me to define the controls that I desire to validate within the web page.

 


View Entire Article

User Comments

Title: Kevin-Rookie   
Name: JamesT
Date: 2009-01-08 1:51:13 PM
Comment:
Kevin, you are a rookie. A custom validation control is needed when the current controls do not meet your criteria.
Some validation rules are too complex and require custom handling.
Title: very very thanks   
Name: s/w eng. Rituraj pandey
Date: 2008-11-20 1:25:25 AM
Comment:
hi, i am very-2 thak full to you because this is a greated need to me and this is a great help to me so thank you.
Title: No   
Name: Kevin
Date: 2008-06-27 7:26:45 AM
Comment:
No, this is not helpfull. Why does every one want to increase the file size by creating custom validations as a script. Use the syntax when you assign the validation to a text box or field
Title: custom control   
Name: Rahul
Date: 2007-09-05 7:00:00 AM
Comment:
thnx give the best examples.so that we can learn more info abt custom validation.
Regards,
Rahul
Title: Code Download Available?   
Name: Edward
Date: 2007-07-02 12:35:39 PM
Comment:
Is the complete code download available?

Thanks,
Ed
Title: Microsoft Validation for Custom Controls?   
Name: Alfred
Date: 2005-11-04 12:13:57 PM
Comment:
Thank you for your article, I would like to ask you how to create user control that standard validation control can recognise it, that is UserControl name will appear in ControlToValidate list?
Thank you.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-12-11 8:54:39 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search