0

I render some markup dynamically in a Web User Control, can I get that out in design mode, and not only runtime?

public override void RenderControl(HtmlTextWriter writer)
{
 if (this.DesignMode) 
  writer.Write("<p>In design mode</p>");
 else
  base.RenderControl(writer);
}

... nothing happens when I check the design view of the control. Not if I remove the if (this.DesignMode)-condition either.

Will I need to use a Server Control?

joeriks
  • 3,382
  • 8
  • 32
  • 42
  • 1
    Yes. Web Control = compiled, no designer - manual rendering. Server Control = designer, markup, markup compiled at runtime. – RPM1984 Sep 29 '10 at 08:48

3 Answers3

1

You will need to create a custom designer for your control. Start reading about it on MSDN

TheGeekYouNeed
  • 7,509
  • 2
  • 26
  • 43
1

It is not possible with a Control deriving from UserControl. Also see How to hide the inner controls of a UserControl in the Designer?

Community
  • 1
  • 1
citronas
  • 19,035
  • 27
  • 96
  • 164
0

Visual studio doesn't support this. The moment you specify the word "user control", the thing goes beserk and renders everything you put on it. Apparently this has been the case since 2008...

You can convert your user control to a server control, which is a major pain. Or...

Fortunately you can influence how server controls are rendered. In other words, you can cheat the Visual Studio designer by making use of that. The code you need can be found here: http://www.codeproject.com/Tips/773145/Hiding-contents-in-ASP-Net-user-control-designer

atlaste
  • 30,418
  • 3
  • 57
  • 87