CreateChildControl vs RenderContents

Discussion in 'ASP .Net Web Controls' started by Paul S, Feb 22, 2010.

  1. Paul S

    Paul S Guest

    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
    Paul S, Feb 22, 2010
    #1
    1. Advertising

  2. Paul S

    Hemant Guest

    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" <> wrote in message
    news:...
    > 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, Feb 23, 2010
    #2
    1. Advertising

  3. Paul S

    Paul S Guest

    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:

    > 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" <> wrote in message
    > news:...
    > > 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
    > >

    > .
    >
    Paul S, Feb 23, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Render vs RenderContents

    Alex Nitulescu, Feb 24, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    12,498
    Marc BICHARA
    Aug 17, 2009
  2. Nathan Sokalski
    Replies:
    1
    Views:
    525
    Nathan Sokalski
    Jul 31, 2009
  3. Nathan Sokalski
    Replies:
    1
    Views:
    1,327
    Nathan Sokalski
    Jul 31, 2009
  4. Doug Holland

    RenderContents

    Doug Holland, Sep 17, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    150
    Doug Holland
    Sep 17, 2004
  5. CreateChildControl() fires First

    , Jun 15, 2007, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    731
Loading...

Share This Page