CreateChildControl vs RenderContents

P

Paul S

I'm creating a Custom Server Control
public class DataFormControl : CompositeControl, INamingContainer

The controls are added dynamically depending on the values set on the
properties.

Do I need to go through my logic to determine what controls to add twice -
first when I create the controls in CreateChildControls and the in
RenderContent to render the controls?

or am I just of track here?.

I would appreciate some clarification

Thanks
Paul S
 
H

Hemant

You can either use CreateChildControls or Rendercontaint.
if you want to use child controls you can use createchild controls(other
controls like textbox etc) or you want to dynamically output html then use
rendercontaint.

Hemant
 
P

Paul S

If I do this nothing gets rendered - what do I need to do also?

PlaceHolder ph;
protected override void CreateChildControls()
{
base.CreateChildControls();
this.ph = new PlaceHolder();

TextBox tb = new TextBox();
tb.Text = this.Text;
Button bt = new Button();
bt.Text = "Click";


ph.Controls.Add(tb);
ph.Controls.Add(bt);

this.Controls.Add(ph);
}
protected override void RenderContents(HtmlTextWriter writer)
{
ph.RenderControl(writer);
}
 

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,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top