Thoughts, Tips and Tricks on what I'm currently do for a living. Currently most of my spare time is spent on contributing to Akka.NET.

Friday, May 18, 2007

Passing values to behavior properties

Typically a property in a AjaxControlToolkit Extender looks like this:
public string MyProperty
  get { ... }
  set { ... }
Which will match a property in the behavior:
get_MyProperty : function() { ... },
set_MyProperty : function(value) { ... }
Values for MyProperty on the server side will end up in the behavior. Sometimes you want to pass values to the behavior without creating a property in the Extender control. To do this, simply override RenderScriptAttributes() and add the properties using AddProperty().
protected override void RenderScriptAttributes(ScriptBehaviorDescriptor descriptor)
  string horizontalAlignment=GetHorizontalAlignment();
  descriptor.AddProperty("HorizontalAlignment", horizontalAlignment);
And voilà, the HorizontalAlignment property in the beahvior will be set.

No comments:

Post a Comment