Update Panel .NET

Exploring Microsoft ASP.NET AJAX and jQuery

Archive for the ‘Microsoft ASP.NET AJAX’ Category

Microsoft AJAX Library Preview 6 Available

leave a comment »

Written by tzkuei

October 19, 2009 at 8:59 am

ASP.NET AJAX Validator

with one comment

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:

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

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

public static ValidationResult YourValidationMethod(string value)

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

protected override bool OnServerValidate(string value)
{
    var result = YourValidationMethod(value);
    return result.IsValid;
}

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

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

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

Type.registerNamespace("Example");
Example.YourValidator = function(element) {
    Example.YourValidator.initializeBase(this, [element]);
};
Example.YourValidator.prototype = {
    // Override validate to do pre-validation checks.
    validate: function(val, args, event) {
        Example.YourValidator.callBaseMethod(this, "validate", [val, args, event]);
    },
    // Override validated to do post-validation stuff.
    validated: function(result, event) {
        var val = this.get_element();
        // Do your custom validation message display stuff here!
    }
};
Example.YourValidator.registerClass("Example.YourValidator", UPDN.AjaxValidator);

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

[WebMethod]
public static ValidationResult YourValidationPageMethod(string domain)
{
    return YourValidator.YourValidationMethod(domain);
}

7. Add reference to your validation control in Web.config:

<pages>
    <controls>
    ...
        <add tagPrefix="example" namespace="Example"/>
    </controls>
</pages>

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

<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.

Written by tzkuei

September 11, 2009 at 1:02 pm

ASP.NET AJAX 4.0 Preview 4 Available

leave a comment »

ASP.NET AJAX 4.0 Preview 4 is available for download.

This release contains a preview version of the following features:

  •  
    • ADO.NET Data Services support
    • WCF and ASMX Web service integration
    • ASP.NET AJAX Client Templates
    • Declarative instantiation of client-side controls and behaviors
    • Observable pattern for plain JavaScript objects
    • Live Bindings
    • Markup Extensions
    • DataView control and DataContext component
    • Command Bubbling
    • Change tracking and identity management
    • Support for managing complex links and associations between entities from multiple entity sets or tables
    • Extension methods allowing change tracking and read-write client-server scenarios using other JSON services, including RESTful or JSONP based services

Written by tzkuei

April 1, 2009 at 8:15 am