Overview

Username Availability Validator a.k.a UAV is normal validator control built with ASP.NET AJAX. It is used to validate the availablity of selected username in any data source using customized web service or page method.
The server control directly inherits from BaseValidator class & implements IScriptControl.
Inheriting from BaseValidator means that the control inherites all useful properties such ErrorMessage, Text, ValidationGroup, CssClass, Display etc...

Implemeting IScriptControl on the other hand defines methods that the control must implement to define resources in AJAX-enabled applications such as GetScriptDescriptors and GetScriptReferences.

Properties

  • ServicePath: Path of the web service that is responsible to check for UserName availability. Checkout Communication Method thread in discussion
  • ServiceMethod: Name of the web method in the web service specified in ServicePath that is responsible for performing the logic to check for UserName availability. It is called when the validation process starts. This method must accept one parameter string called "username" and returns a boolean value. Checkout Communication Method thread in discussion
  • MinimumLength: Gets or sets a value indicating minimum number of characters in UserName before validation process take place.
  • ValidateOnKeyPress: A boolean value that indicates whether the validation process should take place upon keypress or not.
  • KeyPressDelay: Gets and sets a value indicating how long after keyup validation happens. Only has effect with ValidateOnKeyPress is set to true.

ASPX Sample

<asp:TextBox ID="UserName" runat="server" />
<encosia:UsernameAvailabilityValidator 
     ControlToValidate="UserName" 
     CssClass="taken"
     Text="Username is taken"
     ErrorMessage="Username is taken"
     KeyPressDelay="500"
     MinimumLength="5" 
     ServiceMethod="IsUsernameAvailable"
     ServicePath="~/MembershipService.asmx"
     ValidateOnKeyPress="True"
     runat="server"/>

Web Service Sample

The following Code snippet defines the service with its method that is used to identify if the username is available or not.
using System.Web.Services;
using System.Web.Script.Services;

[ScriptService]
public class MembershipService : System.Web.Services.WebService
{
    [WebMethod]
    public bool IsUsernameAvailable(string username)
    {
        //Check if username Available using basic ASP.NET Membership Provider Service
        return System.Web.Security.Membership.GetUser(username) == null;        
    }
}

Blog Posts

Live Demos

Last edited Jan 4, 2009 at 7:35 PM by mosessaur, version 5

Comments

victorbustos May 7, 2012 at 4:59 PM 
Good job, has been replaced some appareance but in general the functionality works perfect.

Thanks...