• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

ASP.NET AJAX Validator ...

As promised weeks ago, here is my ASP.NET AJAX validation control “framework”.

To create your own AJAX validation control:

1. Create a new class which inherits UPDN.AjaxValidator:

1.public class YourValidator : UPDN.AjaxValidator { /*...*/ }

2. Provide a public static method to perform the validation, the signature of the method should be:

1.public static ValidationResult YourValidationMethod(string value)

3. Override OnServerValidate to call your public static validation method:

1.protected override bool OnServerValidate(string value)
2.{
3.    var result = YourValidationMethod(value);
4.    return result.IsValid;
5.}

4. Override GetScriptReferences to include your client-side script:

1.protected override void GetScriptReferences(ScriptReferenceCollection references)
2.{
3.    base.GetScriptReferences(references);
4.    references.Add(new ScriptReference("~/Scripts/YourValidator.js"));
5.}

5. Create the client-side control for your validation control, which inherits UPDN.AjaxValidator:

01.Type.registerNamespace("Example");
02.Example.YourValidator = function(element) {
03.    Example.YourValidator.initializeBase(this, [element]);
04.};
05.Example.YourValidator.prototype = {
06.    // Override validate to do pre-validation checks.
07.    validate: function(val, args, event) {
08.        Example.YourValidator.callBaseMethod(this, "validate", [val, args, event]);
09.    },
10.    // Override validated to do post-validation stuff.
11.    validated: function(result, event) {
12.        var val = this.get_element();
13.        // Do your custom validation message display stuff here!
14.    }
15.};
16.Example.YourValidator.registerClass("Example.YourValidator", UPDN.AjaxValidator);

6. Expose the YourValidationMethod method in YourValidator class as a “Page Method” in the code-behind:

1.[WebMethod]
2.public static ValidationResult YourValidationPageMethod(string domain)
3.{
4.    return YourValidator.YourValidationMethod(domain);
5.}

7. Add reference to your validation control in Web.config:
view source
print?
1.<pages>
2.    <controls>
3.    ...
4.        <add tagPrefix="example" namespace="Example"/>
5.    </controls>
6.</pages>

8. Add the validation control to your page, set the PageMethodName property to “YourValidationPageMethod”:

1.<example:YourValidator runat="server" ID="YourValidator1" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Your error message" PageMethodName="YourValidationMethod" ProgressIndicatorCssClass="wait" />

Download the (VS.NET 2008) solution from my SkyDrive.

 Original Source:
http://updatepanel.wordpress.com/2009/09/11/asp-net-ajax-validator/

AddThis Social Bookmark Button

Posted at 10:02:05 am | Permalink | Posted in .Net  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Top Stuff

e-messenger

MSN Web Messenger

eBuddy

ASP.NET Ajax CalendarExtender and Validation

AIM Express

Ajax Tools for ASP.NET Developers



About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (176)
  • Ajax (112)
  • Ajax Games (10)
  • Articles (95)
  • Bookmarking (35)
  • Calendar (21)
  • Chat (45)
  • ColdFusion (3)
  • CSS (84)
  • Email (23)
  • Facebook (84)
  • Flash (20)
  • Google (54)
  • Html (29)
  • Image (12)
  • International Calls & VOIP (7)
  • Java (58)
  • Javascript (280)
  • jQuery (200)
  • JSON (75)
  • Perl (2)
  • PHP (172)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (8)
  • Ruby (32)
  • Storage (4)
  • Toolkits (103)
  • Tutorials (227)
  • UI (11)
  • Utilities (174)
  • Web2.0 (18)
  • XmlHttpRequest (29)
  • YUI (13)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange