Enhanced Validation Control Which Provides Adding Multiple Validation Rules + NHibernate.Validator Support

Hello,

I am toying with something at the moment which I thought I would briefly share and see if there is any interest, my current sample is very raw and I will not post any code. But the idea is that you would do something like this for validation:

           First Name: <asp:TextBox ID="FirstNameText" runat="server"></asp:TextBox> <br /><br />
           
            <cc1:EnhancedValidatorControl ID="EnhancedValidationControl" runat="server" ControlToValidate="FirstNameText">                           
                <ValidationRules>                   
                    <cc1:PropertyBasedValidationRule Property="FirstName" Type="Validator.Model.Person, Validator" />
                </ValidationRules>               
            </cc1:EnhancedValidatorControl>
           
            Last Name: <asp:TextBox ID="LastNameTest" runat="server"></asp:TextBox> <br /><br />
           
            <cc1:EnhancedValidatorControl ID="EnhancedValidatorControl1" runat="server" ControlToValidate="LastNameTest">                           
                <ValidationRules>                   
                    <cc1:PropertyBasedValidationRule Property="LastName" Type="Validator.Model.Person, Validator" />
                </ValidationRules>               
            </cc1:EnhancedValidatorControl>
                       
            Age: <asp:TextBox ID="AgeText" runat="server"></asp:TextBox> <br /><br />
           
            <cc1:EnhancedValidatorControl ID="EnhancedValidatorControl2" runat="server" ControlToValidate="AgeText">                           
                <ValidationRules>  
                    <cc1:RequiredValidationRule Message="Age required" />
                    <cc1:RegexValidationRule ValidationRegex="[0-9]+" Message="Age must be numeric" />                
                    <cc1:PropertyBasedValidationRule Property="Age" Type="Validator.Model.Person, Validator" />
                </ValidationRules>               
            </cc1:EnhancedValidatorControl>
           
            <asp:Button ID="btn" runat="server" Text="Go" />

 

And the model would look like so decorated with NHibernate.Validator attributes:

public class Person {

        public int Id { get; set; }
       
        [NotEmpty(Message="First name should not be empty.")]
        [Length(0, 10, Message = "First name should be less than 10 chars")]
        public string FirstName { get; set; }
       
        [NotEmpty(Message = "Last name should not be empty")]
        public string LastName { get; set; }
       
        [Range(1, 99, Message= "Age should be between 1 and 99")]
        public int Age { get; set; }       
       
    }

As you can see we can easily and in a nice format use both client side validators + the server side proxies to the NHibernate.Validator attribute based validation (could be used to use the MS Validation Block proxies too). This also automatically wires in an AjaxCalloutExtender so we get the nice callout for both the client side and server side handlers. This seems to work quite well at the moment. I am going to tidy up and release this if there is enough interest expressed in something like this.

Any feedback/suggestions would be appreciated.

 

Thanks
Stefan

No Comments