The declarative approach: attaching MS controls and behaviors
As we’ve seen in a previous post, the latest release of MS AJAX (preview 5 at the time of writing) lets us use a declarative approach to create and attach a MS control with an existing HTML DOM node. Lets recover the example we’ve used:
Using the sys:attach results in getting a new Sys.UI.DataView control and attaching it to the UL element. You already know this. What I didn’t mention at the time was that you can use the same approach for attaching behaviors to existing controls. For instance, the next snippet shows how to use a declarative approach to associate a watermark behavior with an existing textbox:
This might be a good way of letting your designers add stuff to your pages. Btw, you should notice that the ASP.NET 4.0 white paper has a section called “declarative Instantiation Outside a Template” on it which says that you’ll need to activate the control if its placed outside a template. I’ve run the previous sample without activating it and it works, so I’m not sure if things have change or will change with a future release.
And that’s it. Stay tuned for more on MS AJAX.