Dynamic HttpTableRow not rendering cell content...

Discussion in 'ASP .Net' started by David Whitney, Jul 17, 2003.

  1. All:

    I have a control that renders a table. As the table is rendered, each
    row in the table is constructed by creating a run-time (dynamic)
    object that is derived from an HtmlTableRow. The row has three
    HtmlTableCell objects, and each cell contains a single control added
    to the HtmlTableCell's Controls collection. The basic table renders
    correctly, but the controls within the HtmlTableCell objects do not;
    the cells are just empty. (Just <TD></TD> tags).

    I add the controls to each cell in my derived class constructor, and
    that code fires in the debugger. The controls just don't render.

    I'm sure there is a very basic problem I'm overlooking, but I'm
    stymied as to what it is.

    I'd greatly appreciate any thoughts.

    David

    ps Please reply to group; email in message is long since dead.
    David Whitney, Jul 17, 2003
    #1
    1. Advertising

  2. David,
    Did you override the render method in the class that derives from
    HtmlTableRow? Something like this:
    protected override void Render(HtmlTextWriter writer)
    {
    writer.Write(this.Text);
    }

    You didn't provide any code so I'm asking the obvious.

    Louis Dascoulias, AWS

    "David Whitney" <> wrote in message
    news:...
    > All:
    >
    > I have a control that renders a table. As the table is rendered, each
    > row in the table is constructed by creating a run-time (dynamic)
    > object that is derived from an HtmlTableRow. The row has three
    > HtmlTableCell objects, and each cell contains a single control added
    > to the HtmlTableCell's Controls collection. The basic table renders
    > correctly, but the controls within the HtmlTableCell objects do not;
    > the cells are just empty. (Just <TD></TD> tags).
    >
    > I add the controls to each cell in my derived class constructor, and
    > that code fires in the debugger. The controls just don't render.
    >
    > I'm sure there is a very basic problem I'm overlooking, but I'm
    > stymied as to what it is.
    >
    > I'd greatly appreciate any thoughts.
    >
    > David
    >
    > ps Please reply to group; email in message is long since dead.
    Louis Dascoulias, Jul 17, 2003
    #2
    1. Advertising

  3. The short answer is no, I didn't, but here's why I didn't...

    I presumed, probably incorrectly, that each element still knows how to
    render itself, and that rendering a table row would be a matter of
    rendering a cell, then its contents, etc, then the next cell, its
    contents, etc... which would be part of its default behavior.

    The code is essentially like this - note this is just scratched out
    from memory - I'm away from my source at the moment.

    public void MyDerivedHtmlTableRow(string somevalue)
    {
    HtmlTableCell hc = new HtmlTableCell();
    HtmlInputBox ib = new HtmlInputBox();
    ib.Text=somevalue;

    hc.Controls.Add(ib);

    //... add two other cells/controls similarly

    this.Cells.Add(hc);
    }

    The calling class - a control - uses it like this:

    public void AddTableRow()
    {
    for (x=1;x<=10;x++)
    table.Rows.AddAt(number,
    new MyDerivedTableRow(System.Convert.ToString(x))));
    }

    Since the *rows* rendered, but just not their contents, it seemed I
    didn't need to implement custom rendering; the controls on each table
    cell were not being rendered. If I'm just missing the boat on where to
    do some rendering overrides, that's cool, I'm just trying to figure
    out the right place...and a bit of where I might be confused..or is it
    something as simple as

    protected override void Render(HtmlTextWriter writer)
    {
    writer.Write(<TR>);
    //custom render the first cell, and its one child control??
    //custom render the second cell??
    writer.Write(</TR>);

    //or

    //call an existing rendering method on the cell and its child
    control??
    }

    Thoughts? (And thanks for your help, too!)

    -David



    "Louis Dascoulias" <> wrote in message news:<>...
    > David,
    > Did you override the render method in the class that derives from
    > HtmlTableRow? Something like this:
    > protected override void Render(HtmlTextWriter writer)
    > {
    > writer.Write(this.Text);
    > }
    >
    > You didn't provide any code so I'm asking the obvious.
    >
    > Louis Dascoulias, AWS
    >
    > "David Whitney" <> wrote in message
    > news:...
    > > All:
    > >
    > > I have a control that renders a table. As the table is rendered, each
    > > row in the table is constructed by creating a run-time (dynamic)
    > > object that is derived from an HtmlTableRow. The row has three
    > > HtmlTableCell objects, and each cell contains a single control added
    > > to the HtmlTableCell's Controls collection. The basic table renders
    > > correctly, but the controls within the HtmlTableCell objects do not;
    > > the cells are just empty. (Just <TD></TD> tags).
    > >
    > > I add the controls to each cell in my derived class constructor, and
    > > that code fires in the debugger. The controls just don't render.
    > >
    > > I'm sure there is a very basic problem I'm overlooking, but I'm
    > > stymied as to what it is.
    > >
    > > I'd greatly appreciate any thoughts.
    > >
    > > David
    > >
    > > ps Please reply to group; email in message is long since dead.
    David Whitney, Jul 17, 2003
    #3
  4. David,

    It finally occured to me: you must assign an ID to the child control.
    Nothing will automatically assign one to the control.

    Previous thoughts:
    You may need to call EnsureChildControls at some point after adding
    the textboxes to the cell since the textboxes aren't a component/property
    of the cells.

    I played around with createing 'table-maker' controls in VB.Net a while back
    so I can provide some code if needed..

    Louis Dascoulias, AWS



    "David Whitney" <> wrote in message
    news:...
    > The short answer is no, I didn't, but here's why I didn't...
    >
    > I presumed, probably incorrectly, that each element still knows how to
    > render itself, and that rendering a table row would be a matter of
    > rendering a cell, then its contents, etc, then the next cell, its
    > contents, etc... which would be part of its default behavior.
    >
    > The code is essentially like this - note this is just scratched out
    > from memory - I'm away from my source at the moment.
    >
    > public void MyDerivedHtmlTableRow(string somevalue)
    > {
    > HtmlTableCell hc = new HtmlTableCell();
    > HtmlInputBox ib = new HtmlInputBox();
    > ib.Text=somevalue;
    >
    > hc.Controls.Add(ib);
    >
    > //... add two other cells/controls similarly
    >
    > this.Cells.Add(hc);
    > }
    >
    > The calling class - a control - uses it like this:
    >
    > public void AddTableRow()
    > {
    > for (x=1;x<=10;x++)
    > table.Rows.AddAt(number,
    > new MyDerivedTableRow(System.Convert.ToString(x))));
    > }
    >
    > Since the *rows* rendered, but just not their contents, it seemed I
    > didn't need to implement custom rendering; the controls on each table
    > cell were not being rendered. If I'm just missing the boat on where to
    > do some rendering overrides, that's cool, I'm just trying to figure
    > out the right place...and a bit of where I might be confused..or is it
    > something as simple as
    >
    > protected override void Render(HtmlTextWriter writer)
    > {
    > writer.Write(<TR>);
    > //custom render the first cell, and its one child control??
    > //custom render the second cell??
    > writer.Write(</TR>);
    >
    > //or
    >
    > //call an existing rendering method on the cell and its child
    > control??
    > }
    >
    > Thoughts? (And thanks for your help, too!)
    >
    > -David
    >
    >
    >
    > "Louis Dascoulias" <> wrote in message

    news:<>...
    > > David,
    > > Did you override the render method in the class that derives from
    > > HtmlTableRow? Something like this:
    > > protected override void Render(HtmlTextWriter writer)
    > > {
    > > writer.Write(this.Text);
    > > }
    > >
    > > You didn't provide any code so I'm asking the obvious.
    > >
    > > Louis Dascoulias, AWS
    > >
    > > "David Whitney" <> wrote in message
    > > news:...
    > > > All:
    > > >
    > > > I have a control that renders a table. As the table is rendered, each
    > > > row in the table is constructed by creating a run-time (dynamic)
    > > > object that is derived from an HtmlTableRow. The row has three
    > > > HtmlTableCell objects, and each cell contains a single control added
    > > > to the HtmlTableCell's Controls collection. The basic table renders
    > > > correctly, but the controls within the HtmlTableCell objects do not;
    > > > the cells are just empty. (Just <TD></TD> tags).
    > > >
    > > > I add the controls to each cell in my derived class constructor, and
    > > > that code fires in the debugger. The controls just don't render.
    > > >
    > > > I'm sure there is a very basic problem I'm overlooking, but I'm
    > > > stymied as to what it is.
    > > >
    > > > I'd greatly appreciate any thoughts.
    > > >
    > > > David
    > > >
    > > > ps Please reply to group; email in message is long since dead.
    Louis Dascoulias, Jul 17, 2003
    #4
    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. hazz
    Replies:
    6
    Views:
    49,435
    SkyUCHC
    Jun 9, 2010
  2. Peter Mount
    Replies:
    4
    Views:
    933
    Peter Mount
    Jan 31, 2006
  3. =?Utf-8?B?R1RC?=

    Content Not Rendering in Master Page

    =?Utf-8?B?R1RC?=, Jul 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    606
    Craig
    Sep 27, 2006
  4. Kurt
    Replies:
    0
    Views:
    181
  5. Replies:
    2
    Views:
    235
    Thomas 'PointedEars' Lahn
    Aug 5, 2008
Loading...

Share This Page