Tuesday 5 June 2007

Ajax Extender Properties Gotchas

When you want to add a property to an Ajax Extender you need to do the following.

Make sure you have installed the Ajax Extender Templates, run AjaxControlExtender.vsi from the AjaxControlExtender directory of your toolkit install.

Create a new item using the ASP.NET Ajax Extender Control Template from my templates.

Note : If you set the namespace to have a . in it e.g. Company.AjaxControls then the Javascript will not be able to find the script as a webresource. If you want to do this then you have to manually change the ClientScriptResource attribute of the extender.


1) Create the C# Property in the controlExtender.cs file

[ExtenderControlProperty]
[RequiredProperty]
public string ExampleControl
{
get { return GetPropertyValue("ExampleControl", ""); }
set { SetPropertyValue("ExampleControl", value); }
}

2) Create the JavaScript Property in the controlBehaviour.js file
  • In the function(element) section, at the top of the page by the todo 1 to declare the property on the JavaScript side

    this._ExampleControl = null;

  • Add the property getter and setters at the bottom of the file

    get_ExampleControl : function() {
    return this._ExampleControl;
    },

    set_ExampleControl : function(value) {
    this._ExampleControl = value;
    },
Note : The getter and setters are named get_(propertyname) and set_(propertyname). the asp.net Ajax controls expect the names in this form.