protected override void CreateChildControls()

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default protected override void CreateChildControls()

    Hi!
    I'm creating a custom Server Control which implements the method in the
    subject line (Protected override void CreateChildControls)

    In here I have the following code:

    LBL myLbl = new LBL();
    myLbl.ID = "MyLbl";
    myLbl.Text = objCustomFieldUtil.GetName("custom");
    this.Controls.Add(new LiteralControl("<td class=\"regLabelCell\">"));
    this.Controls.Add(myLbl);
    this.Controls.Add(new LiteralControl("</td>"));

    Now what I'd like to do is add the child controls dynamically by looping
    through a Data Table:

    for(int i = 0; i < objDT.Rows.Count; i++)
    {
    //Implement Adding Controls here
    }

    The problem arises that I need to declare my label or textbox before I can
    added it. Anyone know a way around this?

    Thank you.







    Jon Guest

  2. Similar Questions and Discussions

    1. properties going to void
      "Stephen Whipp" <Stephen.Whipp@btopenworld.com> wrote in message news:bkt355$p90$1@forums.macromedia.com... Are you sure the marker isn't on the...
    2. Should VOID = 0?
      Just wondering what you think about VOID being equal to 0? Personally I wish that void didn't equal 0 as it can cause problems for some checks,...
    3. voidP() and variable = VOID with integers with a value of 0
      note that voidp(whatever) is a function returning true (1) if 'whatever' is equivalent to VOID. when you do: put vZero = VOID the program...
    4. CreateChildControls?
      Hi. I have an HTML page were I load controls dynamically. So I overwrote the CreateChildControl but I found some problem. First time when page...
    5. Static void
      Hi, In a gnu/linux env, I have a library exposes one function foo() to a multithreaded server application. Here are my questions: 1. any...
  3. #2

    Default Re: protected override void CreateChildControls()

    Jon, it's not a problem:

    for(into I = 0; I < bond.Rows.Count; I++)
    {
    Label aspLabel = new Label();
    aspLabel.ID = "Label" + I.ToString();
    aspLabel.Text = bond.Rows[I]["field"];
    this.Controls.Add(aspLabel);
    }

    Of course, you want to do this in the right place, and maybe you want to
    enclose each label in a "<td></td>".
    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]

    P.S. Did you do this.Controls.Clear() at the beginning of
    CreateChildControls?

    "Jon" <anon@covad.net> wrote in message
    news:bgs54n$v6n$1@sun-news.laserlink.net...
    > Hi!
    > I'm creating a custom Server Control which implements the method in
    the
    > subject line (Protected override void CreateChildControls)
    >
    > In here I have the following code:
    >
    > LBL myLbl = new LBL();
    > myLbl.ID = "MyLbl";
    > myLbl.Text = objCustomFieldUtil.GetName("custom");
    > this.Controls.Add(new LiteralControl("<td class=\"regLabelCell\">"));
    > this.Controls.Add(myLbl);
    > this.Controls.Add(new LiteralControl("</td>"));
    >
    > Now what I'd like to do is add the child controls dynamically by looping
    > through a Data Table:
    >
    > for(int i = 0; i < objDT.Rows.Count; i++)
    > {
    > //Implement Adding Controls here
    > }
    >
    > The problem arises that I need to declare my label or textbox before I can
    > added it. Anyone know a way around this?
    >
    > Thank you.
    >
    >
    >
    >
    >
    >
    >

    John Saunders Guest

  4. #3

    Default Re: protected override void CreateChildControls()

    John,
    Thanks...Sorry for not trying that first (makes me look like a
    dumba$$ In my defense it was late and I was on the way out :-) )

    I did not do this.Controls.Clear(), what does that do exactly...remove all
    references to child controls on the postback?

    Thanks,

    Jon

    "John Saunders" <john.saunders@surfcontrol.com> wrote in message
    news:OnUoifIXDHA.1492@TK2MSFTNGP12.phx.gbl...
    > Jon, it's not a problem:
    >
    > for(into I = 0; I < bond.Rows.Count; I++)
    > {
    > Label aspLabel = new Label();
    > aspLabel.ID = "Label" + I.ToString();
    > aspLabel.Text = bond.Rows[I]["field"];
    > this.Controls.Add(aspLabel);
    > }
    >
    > Of course, you want to do this in the right place, and maybe you want to
    > enclose each label in a "<td></td>".
    > --
    > John Saunders
    > Internet Engineer
    > [email]john.saunders@surfcontrol.com[/email]
    >
    > P.S. Did you do this.Controls.Clear() at the beginning of
    > CreateChildControls?
    >
    > "Jon" <anon@covad.net> wrote in message
    > news:bgs54n$v6n$1@sun-news.laserlink.net...
    > > Hi!
    > > I'm creating a custom Server Control which implements the method in
    > the
    > > subject line (Protected override void CreateChildControls)
    > >
    > > In here I have the following code:
    > >
    > > LBL myLbl = new LBL();
    > > myLbl.ID = "MyLbl";
    > > myLbl.Text = objCustomFieldUtil.GetName("custom");
    > > this.Controls.Add(new LiteralControl("<td class=\"regLabelCell\">"));
    > > this.Controls.Add(myLbl);
    > > this.Controls.Add(new LiteralControl("</td>"));
    > >
    > > Now what I'd like to do is add the child controls dynamically by looping
    > > through a Data Table:
    > >
    > > for(int i = 0; i < objDT.Rows.Count; i++)
    > > {
    > > //Implement Adding Controls here
    > > }
    > >
    > > The problem arises that I need to declare my label or textbox before I
    can
    > > added it. Anyone know a way around this?
    > >
    > > Thank you.
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    >
    >

    Jon Guest

  5. #4

    Default Re: protected override void CreateChildControls()

    "Jon" <anon@covad.net> wrote in message
    news:bgu4nh$9am$1@sun-news.laserlink.net...
    > John,
    > Thanks...Sorry for not trying that first (makes me look like a
    > dumba$$ In my defense it was late and I was on the way out :-) )
    >
    > I did not do this.Controls.Clear(), what does that do exactly...remove all
    > references to child controls on the postback?
    Controls.Clear() removes all of your child controls. You do it at the
    beginning of CreateChildControls to ensure that the set of child controls is
    exaclty the set created in CreateChildControls.

    Now, I never quite tracked it down, but I've had problems with
    CreateChildControls being called twice. Calling Controls.Clear solved the
    problem.

    --
    John Saunders
    Internet Engineer
    [email]john.saunders@surfcontrol.com[/email]



    John Saunders Guest

  6. #5

    Default Re: protected override void CreateChildControls()

    Cool, thanks for the tip and all the help.

    -Jon


    "John Saunders" <john.saunders@surfcontrol.com> wrote in message
    news:%23ZWxvDRXDHA.1644@TK2MSFTNGP10.phx.gbl...
    > "Jon" <anon@covad.net> wrote in message
    > news:bgu4nh$9am$1@sun-news.laserlink.net...
    > > John,
    > > Thanks...Sorry for not trying that first (makes me look like a
    > > dumba$$ In my defense it was late and I was on the way out :-) )
    > >
    > > I did not do this.Controls.Clear(), what does that do exactly...remove
    all
    > > references to child controls on the postback?
    >
    > Controls.Clear() removes all of your child controls. You do it at the
    > beginning of CreateChildControls to ensure that the set of child controls
    is
    > exaclty the set created in CreateChildControls.
    >
    > Now, I never quite tracked it down, but I've had problems with
    > CreateChildControls being called twice. Calling Controls.Clear solved the
    > problem.
    >
    > --
    > John Saunders
    > Internet Engineer
    > [email]john.saunders@surfcontrol.com[/email]
    >
    >
    >


    Jonathan Williams Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139