views:

657

answers:

2

I'm wondering if anyone has any experience converting User controls to Web controls?

Ideally, I'd like to offload some of the design work to others, who would give me nicely laid out User Controls. Then, I could go through the process of converting, compiling, testing and deploying.

Until MS comes up with the magic "Convert to Server Control" option, it looks like I'm pretty well stuck with re-writing from scratch. Any ideas?

+2  A: 

Is there a reason you must convert these user controls to server controls? Remember that it is possible to compile a user control into an assembly.

Andrew Hare
Also http://msdn.microsoft.com/en-us/library/aa479318.aspx
Aidan
+1  A: 

You are right there is no magic bullet here but since you already have a User Control its not that difficult.

  1. Make sure all properties, events, etc. are set in the code behind since you won't have any mark up when you're done
  2. Create a new Server Control
  3. Paste all of the event handling and property setting code into the new control
  4. override the Render method for each child control call the RenderControl Method passing in the supplied HtmlTextWriter

    protected override void Render(HtmlTextWriter writer)
    {
     TextBox box = new TextBox();
     //Set all the properties here
     box.RenderControl(writer);
     base.Render(writer);
    }
    
Jeremy