How to use HtmlControlDesigner

  • Thread starter Karsten Lundsgaard
  • Start date
K

Karsten Lundsgaard

Hi,
I'm making some runtime-invisible-WebControls, which
should be visible at designtime like the "Repeater"-
component in the "Web Forms Toolbox", and invisible at
runtime.

I think that I have to use HtmlControlDesigner.

Is there somebody who have an exsample on how to make the
DesignTime render function.

Regards

Karsten Lundsgaard
 
J

John Saunders

I don't get why you couldn't just use a designer derived from
ControlDesigner?

The following example is from "Professional ASP.NET Server Controls",
copyright 2002 Wrox Press, page 345:

public class WroxButtonDesigner : ControlDesigner
{
public WroxButtonDesigner()
{
}

public override string GetDesignTimeHtml()
{
// Get a typed reference to the button being designed.
WroxButton wb = (WroxButton) base.Component;

Panel pnl = new Panel();
// Make it look just as the button control.
pnl.CopyBaseAttributes(wb);
pnl.Controls.Add(wb);
// Add a dotted border and adjust the new size
pnl.BorderStyle = BorderStyle.Dotted;
pnl.BorderWidth = new Unit(2, UnitType.Point);
pnl.Height = new Unit(pnl.Height.Value + 4);
pnl.Width = new Unit(pnl.Width.Value + 4);
// Return the rendered string.
return GetRenderHtml(pnl);
}

/// <summary>
/// Provides the string representation of a rendered control.
/// </summary>
/// <param name="control">The control to render.</param>
/// <returns>The HTML representing the control.</returns>
private string GetRenderHtml(Control control)
{
StringWriter text = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(text);
control.RenderControl(writer);
return text.ToString();
}
}
 
K

Karsten Lundsgaard

Thanks. It seems like the ControlDesigner will do the job.

BTW : The MSDN description of the ControlDesigner Class
has a good example.

Karsten Lundsgaard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top