Rendering Custom Control during design time

J

Joey Lee

Hi,

I have been creating simple custom controls that is able to be added to the
Visual Studio toolbox and drag & drop to my aspx pages. The main thing i
need is visual representation during design time.

In order to do this, i override the render method and insert html codes.

However I would like to do more by inserting web controls, can this be done?
Using other ways like user control or overriding the createchildcontrol of
controls does not allow visual representation design time.

I was thinking of creating a simple control which have a label and a
dropdownlist with autopostback. This control is used to control the display
row for my datagrid. How do i code web controls and allow postback that will
somehow allow me again to change the display row of my data grid.

Any ideas or pointer?

Thanks

Joey
 
M

Matt

What worked for me was to create my own Designer class (extending
System.Web.UI.Design.ControlDesigner). Then you override
GetDesignTimeHtml() method and in that method you can do stuff like:

StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);

Label lblLink = new Label();
lblLink.Text = "<";
lblLink.ForeColor = System.Drawing.Color.Blue;
lblLink.Style.Add("text-decoration", "underline");
lblLink.RenderControl(tw);

If you want to get a reference to the actual control to read a property
or something:

MyCustomControl myCC = (MyCustomControl)this.Component;
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top