skip to the main content area of this page
Patterns and Practices

Validation Guidance Bundle Tutorial - Web Client Software Factory


The Microsoft patterns & practices team released a Validation Guidance Bundle to assist developers in providing a rich user experience with validation in their ASP.NET web applications. The Validation Guidance Bundle is the second guidance bundle released and somewhat helps with the issue of the Validation Application Block requiring a postback for validation. Ther first guidance bundle was the Autocomplete Guidance Bundle.

Included in the Validation Guidance Bundle is a new control, the ServerSideValidationExtender, which offers a way to perform server-side validation over AJAX. You just toss it in your ASP.NET Web Pages as such:

 

ServerSideValidationExtender

 

In this case, the ServerSideValidationExtender helps the NameValidator PropertyProxyValidator Control in the Validation Application Block do its validation without having to click the Add Customer Button. The PropertyProxyValidator gets its validation information from the Customer Class:

 

namespace BusinessEntities
{
    public class Customer
    {
        private string _name;

        [StringLengthValidator(1,5,
            MessageTemplate ="Name length must be between {3} - {5} characters.")]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public Customer() {}
    }
}

 

The ServerSideValidationExtender extends the PropertyProxyValidator to the server over AJAX using the following design-time code in the ASP.NET Page:

 

<ajaxtoolkitwcsfextensions:ServerSideValidationExtender
        ID="NameServerSideValidationExtender"
        runat="server"
        TargetControlID="NameValidator">
</ajaxtoolkitwcsfextensions:ServerSideValidationExtender> 

 

When I type in the name "David Hayden", which is clearly more than 5 characters as specified by the StringLengthValidator on the Name Property of the Customer Class, and press the tab key to fill in the email address, I get the name length error immediately:

 

ServerSideValidationExtender

 

Normally the error wouldn't show up until the Add Customer button was submitted. The ServerSideValidationExtender control sends a partial page postback immediately when you tab to the next control, allowing the StringLengthValidator to do the validation on the information entered into the txtName textbox.

You can see that a partial page postback definitely occurs using Fiddler.

 

ServerSideValidationExtender

 

I question why we still need a Partial Page Postback with the ServerSideValidationExtender control, but I am sure that the Web Client Software Factory team wanted to work with the existing PropertyProxyValidator Control and deal with its limitations of requiring a postback. Either way, this helps provide a more responsive user experience with the PropertyProxyValidator Controls in Enterprise Library.

For more information on the Validation Application Block and PropertyProxyValidator Control in Enterprise Library, check out the screencast:

Validation Application Block and ASP.NET Integration Screencast

For more tutorials on the Validation Application Block, please check out the following tutorials:

 


Tags: GuidanceBundles, ServerSideValidationExtender, PropertyProxyValidator


Topics



Popular Tags



Recent Links