<ASP:Table> problems

Discussion in 'ASP .Net Web Controls' started by Dave Bennett, Jul 15, 2004.

  1. Dave Bennett

    Dave Bennett Guest

    I am hoping someone can help me because I am really beginning to hate IE.

    I am using the following code to generate a dynamic table.
    private void buildTable(ArrayList Products)
    {
    //Variables
    int cnt = Products.Count;
    string key = "";
    Control c;
    TableRow r = new TableRow();
    TableCell Xcell = new TableCell();

    //Add Empty cell
    Xcell.Width=Unit.Parse("100");
    r.Cells.Add(Xcell);

    //Build Product Titles
    for (int i=0;i<cnt;i++)
    {
    TableCell cell = new TableCell();
    cell.CssClass="whiteSub";
    cell.Width=Unit.Pixel(125);
    Label lbl = new Label();
    lbl.ID = "Prod" + (i+1) + "_Nm";
    cell.Controls.Add(lbl);
    r.Cells.Add(cell);
    }
    ProdName.Rows.Add(r);
    }

    When I render in IE it puts the width inside a style tag which I do not
    want. See below for example of rendered HTML.

    <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td style="width:100px;"></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod1_Nm">xxxx</span></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod2_Nm">xxxx</span></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod3_Nm">xxxx</span></td>
    </tr>
    </table>


    In Mozilla Firefox it renders it correctly. See below for example of
    rendered HTML

    <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td width="100"></td>
    <td class="whiteSub" width="125"><span id="Prod1_Nm">xxxx</span></td>
    <td class="whiteSub" width="125"><span id="Prod2_Nm">xxxx</span></td>
    <td class="whiteSub" width="125"><span id="Prod3_Nm">xxxx</span></td>
    </tr>
    </table>

    Can anyone tell what I need to do to make IE render the <ASP:Table>
    correctly?


    Thanks in advance

    Dave Bennett
    Dave Bennett, Jul 15, 2004
    #1
    1. Advertising

  2. Dave Bennett

    Scott G. Guest

    By default ASP.NET thinks that Gecko (Mozilla/FireFox) browsers are only HTML 3.2, and thus the rendered HTML you see is different (it's the 3.2 version). If you had a more up to date browserCap, then you'd get the same HTML for both browsers (which would be the HTML with the style= attributes); also, in ASP.NET 2 you'll get the updated browserCap.

    Since it doesn't look like you are using the Table (and TableRow/TableCell) controls for anything but layout; one easy work around would be to just generate the HTML for the table the way you want it and skip the HTML table controls.

    Scott
    "Dave Bennett" <> wrote in message news:...
    I am hoping someone can help me because I am really beginning to hate IE.

    I am using the following code to generate a dynamic table.
    private void buildTable(ArrayList Products)
    {
    //Variables
    int cnt = Products.Count;
    string key = "";
    Control c;
    TableRow r = new TableRow();
    TableCell Xcell = new TableCell();

    //Add Empty cell
    Xcell.Width=Unit.Parse("100");
    r.Cells.Add(Xcell);

    //Build Product Titles
    for (int i=0;i<cnt;i++)
    {
    TableCell cell = new TableCell();
    cell.CssClass="whiteSub";
    cell.Width=Unit.Pixel(125);
    Label lbl = new Label();
    lbl.ID = "Prod" + (i+1) + "_Nm";
    cell.Controls.Add(lbl);
    r.Cells.Add(cell);
    }
    ProdName.Rows.Add(r);
    }

    When I render in IE it puts the width inside a style tag which I do not
    want. See below for example of rendered HTML.

    <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td style="width:100px;"></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod1_Nm">xxxx</span></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod2_Nm">xxxx</span></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod3_Nm">xxxx</span></td>
    </tr>
    </table>


    In Mozilla Firefox it renders it correctly. See below for example of
    rendered HTML

    <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td width="100"></td>
    <td class="whiteSub" width="125"><span id="Prod1_Nm">xxxx</span></td>
    <td class="whiteSub" width="125"><span id="Prod2_Nm">xxxx</span></td>
    <td class="whiteSub" width="125"><span id="Prod3_Nm">xxxx</span></td>
    </tr>
    </table>

    Can anyone tell what I need to do to make IE render the <ASP:Table>
    correctly?


    Thanks in advance

    Dave Bennett
    Scott G., Jul 15, 2004
    #2
    1. Advertising

  3. Dave Bennett

    Sky Sigal Guest

    I thought that "Correct" was Css compliant -- which would make the IE output
    more spec compliant (for once!) than mozilla?

    Anyway - who cares about the output, as long as the SHAPE of the output is
    right? No? Does this cause unexpected layout in either platform?

    That said -- I guess you could always bypass all the fancy wiring ASP.NET
    provides -- and push it in as a plain old Attribute:

    Xcell.Attributes["width"]="100";

    -- although that seems to me to totally defeat the purpose of server side
    controlled rendering....

    PPS:
    What about using CSS class tag instead of inline css/width-- and not loading
    your td's up with inline dimensioning? Makes the payload much less, and
    easier to update the layout at a later date.

    Best of luck,
    Sky


    "Dave Bennett" <> wrote in message
    news:...
    > I am hoping someone can help me because I am really beginning to hate IE.
    >
    > I am using the following code to generate a dynamic table.
    > private void buildTable(ArrayList Products)
    > {
    > //Variables
    > int cnt = Products.Count;
    > string key = "";
    > Control c;
    > TableRow r = new TableRow();
    > TableCell Xcell = new TableCell();
    >
    > //Add Empty cell
    > Xcell.Width=Unit.Parse("100");
    > r.Cells.Add(Xcell);
    >
    > //Build Product Titles
    > for (int i=0;i<cnt;i++)
    > {
    > TableCell cell = new TableCell();
    > cell.CssClass="whiteSub";
    > cell.Width=Unit.Pixel(125);
    > Label lbl = new Label();
    > lbl.ID = "Prod" + (i+1) + "_Nm";
    > cell.Controls.Add(lbl);
    > r.Cells.Add(cell);
    > }
    > ProdName.Rows.Add(r);
    > }
    >
    > When I render in IE it puts the width inside a style tag which I do not
    > want. See below for example of rendered HTML.
    >
    > <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    > <tr>
    > <td style="width:100px;"></td>
    > <td class="whiteSub" style="width:125px;"><span
    > id="Prod1_Nm">xxxx</span></td>
    > <td class="whiteSub" style="width:125px;"><span
    > id="Prod2_Nm">xxxx</span></td>
    > <td class="whiteSub" style="width:125px;"><span
    > id="Prod3_Nm">xxxx</span></td>
    > </tr>
    > </table>
    >
    >
    > In Mozilla Firefox it renders it correctly. See below for example of
    > rendered HTML
    >
    > <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    > <tr>
    > <td width="100"></td>
    > <td class="whiteSub" width="125"><span id="Prod1_Nm">xxxx</span></td>
    > <td class="whiteSub" width="125"><span id="Prod2_Nm">xxxx</span></td>
    > <td class="whiteSub" width="125"><span id="Prod3_Nm">xxxx</span></td>
    > </tr>
    > </table>
    >
    > Can anyone tell what I need to do to make IE render the <ASP:Table>
    > correctly?
    >
    >
    > Thanks in advance
    >
    > Dave Bennett
    >
    >
    >
    >
    Sky Sigal, Jul 15, 2004
    #3
  4. Dave Bennett

    Dave Bennett Guest

    Unfortunately IE is not displaying the CSS style format correctly, which is why I was asking. I am going to try Sky approach and see how I make out.


    Dave
    "Scott G." <> wrote in message news:...

    By default ASP.NET thinks that Gecko (Mozilla/FireFox) browsers are only HTML 3.2, and thus the rendered HTML you see is different (it's the 3.2 version). If you had a more up to date browserCap, then you'd get the same HTML for both browsers (which would be the HTML with the style= attributes); also, in ASP.NET 2 you'll get the updated browserCap.

    Since it doesn't look like you are using the Table (and TableRow/TableCell) controls for anything but layout; one easy work around would be to just generate the HTML for the table the way you want it and skip the HTML table controls.

    Scott
    "Dave Bennett" <> wrote in message news:...
    I am hoping someone can help me because I am really beginning to hate IE.

    I am using the following code to generate a dynamic table.
    private void buildTable(ArrayList Products)
    {
    //Variables
    int cnt = Products.Count;
    string key = "";
    Control c;
    TableRow r = new TableRow();
    TableCell Xcell = new TableCell();

    //Add Empty cell
    Xcell.Width=Unit.Parse("100");
    r.Cells.Add(Xcell);

    //Build Product Titles
    for (int i=0;i<cnt;i++)
    {
    TableCell cell = new TableCell();
    cell.CssClass="whiteSub";
    cell.Width=Unit.Pixel(125);
    Label lbl = new Label();
    lbl.ID = "Prod" + (i+1) + "_Nm";
    cell.Controls.Add(lbl);
    r.Cells.Add(cell);
    }
    ProdName.Rows.Add(r);
    }

    When I render in IE it puts the width inside a style tag which I do not
    want. See below for example of rendered HTML.

    <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td style="width:100px;"></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod1_Nm">xxxx</span></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod2_Nm">xxxx</span></td>
    <td class="whiteSub" style="width:125px;"><span
    id="Prod3_Nm">xxxx</span></td>
    </tr>
    </table>


    In Mozilla Firefox it renders it correctly. See below for example of
    rendered HTML

    <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td width="100"></td>
    <td class="whiteSub" width="125"><span id="Prod1_Nm">xxxx</span></td>
    <td class="whiteSub" width="125"><span id="Prod2_Nm">xxxx</span></td>
    <td class="whiteSub" width="125"><span id="Prod3_Nm">xxxx</span></td>
    </tr>
    </table>

    Can anyone tell what I need to do to make IE render the <ASP:Table>
    correctly?


    Thanks in advance

    Dave Bennett
    Dave Bennett, Jul 16, 2004
    #4
  5. Dave Bennett

    Dave Bennett Guest

    Sky,
    Thanks for your help. As it turns out I am idiot. I thought IE was
    incorrectly display the style tag on the <td> tag. The <td> cell where this
    table was located had a width of 100 which would overrides anything I put in
    my inline table, once I got rid of the width on the parent cell everything
    started looking good! But on the bright side the code you supplied works
    great. Thanks for your input!

    Dave

    "Sky Sigal" <> wrote in message
    news:...
    > I thought that "Correct" was Css compliant -- which would make the IE

    output
    > more spec compliant (for once!) than mozilla?
    >
    > Anyway - who cares about the output, as long as the SHAPE of the output is
    > right? No? Does this cause unexpected layout in either platform?
    >
    > That said -- I guess you could always bypass all the fancy wiring ASP.NET
    > provides -- and push it in as a plain old Attribute:
    >
    > Xcell.Attributes["width"]="100";
    >
    > -- although that seems to me to totally defeat the purpose of server side
    > controlled rendering....
    >
    > PPS:
    > What about using CSS class tag instead of inline css/width-- and not

    loading
    > your td's up with inline dimensioning? Makes the payload much less, and
    > easier to update the layout at a later date.
    >
    > Best of luck,
    > Sky
    >
    >
    > "Dave Bennett" <> wrote in message
    > news:...
    > > I am hoping someone can help me because I am really beginning to hate

    IE.
    > >
    > > I am using the following code to generate a dynamic table.
    > > private void buildTable(ArrayList Products)
    > > {
    > > //Variables
    > > int cnt = Products.Count;
    > > string key = "";
    > > Control c;
    > > TableRow r = new TableRow();
    > > TableCell Xcell = new TableCell();
    > >
    > > //Add Empty cell
    > > Xcell.Width=Unit.Parse("100");
    > > r.Cells.Add(Xcell);
    > >
    > > //Build Product Titles
    > > for (int i=0;i<cnt;i++)
    > > {
    > > TableCell cell = new TableCell();
    > > cell.CssClass="whiteSub";
    > > cell.Width=Unit.Pixel(125);
    > > Label lbl = new Label();
    > > lbl.ID = "Prod" + (i+1) + "_Nm";
    > > cell.Controls.Add(lbl);
    > > r.Cells.Add(cell);
    > > }
    > > ProdName.Rows.Add(r);
    > > }
    > >
    > > When I render in IE it puts the width inside a style tag which I do not
    > > want. See below for example of rendered HTML.
    > >
    > > <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    > > <tr>
    > > <td style="width:100px;"></td>
    > > <td class="whiteSub" style="width:125px;"><span
    > > id="Prod1_Nm">xxxx</span></td>
    > > <td class="whiteSub" style="width:125px;"><span
    > > id="Prod2_Nm">xxxx</span></td>
    > > <td class="whiteSub" style="width:125px;"><span
    > > id="Prod3_Nm">xxxx</span></td>
    > > </tr>
    > > </table>
    > >
    > >
    > > In Mozilla Firefox it renders it correctly. See below for example of
    > > rendered HTML
    > >
    > > <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    > > <tr>
    > > <td width="100"></td>
    > > <td class="whiteSub" width="125"><span id="Prod1_Nm">xxxx</span></td>
    > > <td class="whiteSub" width="125"><span id="Prod2_Nm">xxxx</span></td>
    > > <td class="whiteSub" width="125"><span id="Prod3_Nm">xxxx</span></td>
    > > </tr>
    > > </table>
    > >
    > > Can anyone tell what I need to do to make IE render the <ASP:Table>
    > > correctly?
    > >
    > >
    > > Thanks in advance
    > >
    > > Dave Bennett
    > >
    > >
    > >
    > >

    >
    >
    Dave Bennett, Jul 16, 2004
    #5
  6. Dave Bennett

    Sky Sigal Guest

    Glad I could help :) And even gladder you found what you were looking for
    :)

    "Dave Bennett" <> wrote in message
    news:...
    > Sky,
    > Thanks for your help. As it turns out I am idiot. I thought IE was
    > incorrectly display the style tag on the <td> tag. The <td> cell where

    this
    > table was located had a width of 100 which would overrides anything I put

    in
    > my inline table, once I got rid of the width on the parent cell everything
    > started looking good! But on the bright side the code you supplied works
    > great. Thanks for your input!
    >
    > Dave
    >
    > "Sky Sigal" <> wrote in message
    > news:...
    > > I thought that "Correct" was Css compliant -- which would make the IE

    > output
    > > more spec compliant (for once!) than mozilla?
    > >
    > > Anyway - who cares about the output, as long as the SHAPE of the output

    is
    > > right? No? Does this cause unexpected layout in either platform?
    > >
    > > That said -- I guess you could always bypass all the fancy wiring

    ASP.NET
    > > provides -- and push it in as a plain old Attribute:
    > >
    > > Xcell.Attributes["width"]="100";
    > >
    > > -- although that seems to me to totally defeat the purpose of server

    side
    > > controlled rendering....
    > >
    > > PPS:
    > > What about using CSS class tag instead of inline css/width-- and not

    > loading
    > > your td's up with inline dimensioning? Makes the payload much less, and
    > > easier to update the layout at a later date.
    > >
    > > Best of luck,
    > > Sky
    > >
    > >
    > > "Dave Bennett" <> wrote in message
    > > news:...
    > > > I am hoping someone can help me because I am really beginning to hate

    > IE.
    > > >
    > > > I am using the following code to generate a dynamic table.
    > > > private void buildTable(ArrayList Products)
    > > > {
    > > > //Variables
    > > > int cnt = Products.Count;
    > > > string key = "";
    > > > Control c;
    > > > TableRow r = new TableRow();
    > > > TableCell Xcell = new TableCell();
    > > >
    > > > //Add Empty cell
    > > > Xcell.Width=Unit.Parse("100");
    > > > r.Cells.Add(Xcell);
    > > >
    > > > //Build Product Titles
    > > > for (int i=0;i<cnt;i++)
    > > > {
    > > > TableCell cell = new TableCell();
    > > > cell.CssClass="whiteSub";
    > > > cell.Width=Unit.Pixel(125);
    > > > Label lbl = new Label();
    > > > lbl.ID = "Prod" + (i+1) + "_Nm";
    > > > cell.Controls.Add(lbl);
    > > > r.Cells.Add(cell);
    > > > }
    > > > ProdName.Rows.Add(r);
    > > > }
    > > >
    > > > When I render in IE it puts the width inside a style tag which I do

    not
    > > > want. See below for example of rendered HTML.
    > > >
    > > > <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    > > > <tr>
    > > > <td style="width:100px;"></td>
    > > > <td class="whiteSub" style="width:125px;"><span
    > > > id="Prod1_Nm">xxxx</span></td>
    > > > <td class="whiteSub" style="width:125px;"><span
    > > > id="Prod2_Nm">xxxx</span></td>
    > > > <td class="whiteSub" style="width:125px;"><span
    > > > id="Prod3_Nm">xxxx</span></td>
    > > > </tr>
    > > > </table>
    > > >
    > > >
    > > > In Mozilla Firefox it renders it correctly. See below for example of
    > > > rendered HTML
    > > >
    > > > <table id="ProdName" cellspacing="2" cellpadding="2" border="0">
    > > > <tr>
    > > > <td width="100"></td>
    > > > <td class="whiteSub" width="125"><span id="Prod1_Nm">xxxx</span></td>
    > > > <td class="whiteSub" width="125"><span id="Prod2_Nm">xxxx</span></td>
    > > > <td class="whiteSub" width="125"><span id="Prod3_Nm">xxxx</span></td>
    > > > </tr>
    > > > </table>
    > > >
    > > > Can anyone tell what I need to do to make IE render the <ASP:Table>
    > > > correctly?
    > > >
    > > >
    > > > Thanks in advance
    > > >
    > > > Dave Bennett
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Sky Sigal, Jul 16, 2004
    #6
    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. David Williams
    Replies:
    2
    Views:
    1,107
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Rio
    Replies:
    4
    Views:
    1,174
  3. Replies:
    6
    Views:
    105
  4. Replies:
    0
    Views:
    77
  5. Ted Byers
    Replies:
    9
    Views:
    196
    Ted Byers
    Dec 4, 2008
Loading...

Share This Page