views:

118

answers:

1

Is there a simple process to convert an user control to a web/composite control?

+4  A: 

There's no automatic process, no. Here's the (general) steps to follow though:

  1. Create a webcontrol class. Make it inherit from Panel if you want to take the easy way, or else override the Render() method if you want to generate your HTML the long, verbose way.

  2. Duplicate the layout of the user control by adding html literals and other controls into the Controls collection during Init() or in the constructor for your control class. If you chose to override Render(), you'll need to recursively render the controls.

  3. Copy event handling code-behind from your usercontrol into your class, and wireup the event handlers.

  4. Deal with javascripts/css. You can embed them into your assembly as web resources, or register them as regular includes using ClientScriptManager or ScriptManager.

womp