Thursday, April 20, 2006

Client-side objects for server controls

I had a conversation with Chris Peterson on Tuesday regarding the difficulty of manipulating the HTML controls inside composite or templated .NET controls with Javascript. The controls have ids that you can't easily predict unless you are generating the javascript from within the templated control, and even if you could predict them you'd be violating one of the rules of encapsulation, namely that code manipulating an object (your server control) shouldn't have to know the internals of that control.

Given that Javascript can create objects with arbitrary properties, it occurred to me that it would be possible to expose the objects in a .NET templated control as properties of a client-side object, making them available for manipulating by javascript not generated by the control. Validation controls in .NET 2.0 already do this, using the AddExpandoProperty method of the ClientScriptManager object. I see an area here for experimentation.

0 Comments:

Post a Comment

<< Home