AJAX Properties in Description

I may have mentioned somewhere in my blog that AJAX components go through a process of describing the properties and events (at least) so that the server component can push down values to the client.  This process happens in the GetScriptDescriptors method.  The ScriptDescriptor,which has three deriviatives, notes a component's properties and events by using the following approach:

ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor("<full client class name>", targetControl.ClientID);
descriptor.AddProperty("highlightCellOnMouseOver", this.HighlightCellOnMouseOver);
descriptor.AddProperty("highlightRowOnMouseOver", this.HighlightRowOnMouseOver);

return new ScriptDescriptor[] { descriptor }; 

Notice a few things: first off, the AJAX component I'm creating is a custom extender.  You can tell this because I used ScriptBehaviorDescriptor (I would have used ScriptControlDescriptor for an AJAX control).  The AddProperty method adds properties for the description process; in this way, the AddProperty method passes along a value established on the server to the client, to act as a default value of sorts.

In reality, on the client side those properties have the following definition:

 get_highlightCellOnMouseOver : function()
{
 return this._highlightCellOnMouseOver;
},

set_highlightCellOnMouseOver : function(value)
{
 if (this._highlightCellOnMouseOver != value)
 {
  this._highlightCellOnMouseOver = value;
  this.raisePropertyChanged("highlightCellOnMouseOver");
 }
},

get_highlightRowOnMouseOver : function()
{
 return this._highlightRowOnMouseOver;
},

set_highlightRowOnMouseOver : function(value)
{
 if (this._highlightRowOnMouseOver != value)
 {
  this._highlightRowOnMouseOver = value;
  this.raisePropertyChanged("highlightRowOnMouseOver");
 }
},

So theoretically they can be changed during the client's lifecycle, but at least a default value is established on the server.

Published Monday, August 11, 2008 6:13 AM by bmains
Filed under:

Comments

No Comments