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

Server Side Validation Page 3

VIEWSTATE

 These new properties will allow you to define validatable controls that can be used in your validation process. Since web applications cannot maintain state on its own, you will need a method to do so. Microsoft has provided us with a View State property to maintain state for a page and its controls. A View State is ideal for maintaining the data for a control as the application makes a trip to the server and back to the client. Usually data is lost when the application makes a round trip to the server but with the help of a View State , a control’s value is maintained during this round trip from the client to the server and back.

Each control inherits a View State property from the Control class that you can use when creating your new property within the validation control you are designing.

                    

[
    Category("Behavior"),
    DefaultValue(""),
    Description("The control that the first and second control is dependant on 
    when validating."),

    TypeConverter(typeof(ValidatedControlConverter))
 
                      public string PrimaryControl
                        {
                            get
                                    {
                                                object o = ViewState["PrimaryValue"];
                                                return (o==null) ? String.Empty : (string)o;
                                    }

                                    set
                                    {
                                                ViewState["PrimaryValue"] = value;
                                    }
                        }
               [
                   Category("Behavior"),
                   DefaultValue(""),
                   Description("The first control to validate."),
                   TypeConverter(typeof(ValidatedControlConverter))
               ]        
                      public string FirstControlToValidate

                        {
                                    get

                                    {
                                                object o = ViewState["FirstValue"];                                                 return (o==null) ? String.Empty : (string)o;                                     }

                                    set

                                    {
                                                ViewState["FirstValue"] = value;
                                    }
                        }  
                [

                   Category("Behavior"),
                   DefaultValue(""),
                   Description("The second control to validate."),
                   TypeConverter(typeof(ValidatedControlConverter))

                ]   
                        public string SecondControlToValidate

                        {
                            get

                            {
                                      object o = ViewState["SecondValue"];
                                      return (o==null) ? String.Empty : (string)o;
                            }
                                    set
                                    {
                                                ViewState["SecondValue"] = value;
                                    }
                        }

 

 [Browsable(false)]
Attribute which determines whether a property or event is visible in the properties browser window

 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

Makes the value of the property not visible to the property browser

 


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-2024 ASPAlliance.com  |  Page Processed at 2024-05-18 12:26:03 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search