Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CreateChildControl vs RenderContents

2 views
Skip to first unread message

Paul S

unread,
Feb 22, 2010, 5:26:01 PM2/22/10
to
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

Hemant

unread,
Feb 23, 2010, 1:37:31 AM2/23/10
to
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

"Paul S" <Pa...@discussions.microsoft.com> wrote in message
news:C61F320A-C418-4C8D...@microsoft.com...

Paul S

unread,
Feb 23, 2010, 5:42:03 AM2/23/10
to

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);
}

"Hemant" wrote:

> .
>

0 new messages