Table not showing

Discussion in 'ASP .Net Web Controls' started by Epetruk, Feb 11, 2005.

  1. Epetruk

    Epetruk Guest

    Hi all,

    I'm trying to write a simple page where a table's properties and contained
    controls are generated dynamically.

    I have the following code:



    In Test.aspx:

    <%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false"
    Inherits="Test.TestForm" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>Test</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="TestForm" method="post" runat="server">
    <table id="TestTable" runat="server">
    </table>
    </form>
    </body>
    </HTML>



    In test.aspx.cs:

    public class TestForm : System.Web.UI.Page
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    TestTable = new HtmlTable();
    TestTable.Width = "100%";
    HtmlTableRow rw = new HtmlTableRow();
    HtmlTableCell cl = new HtmlTableCell();
    cl.InnerText = "Test";
    rw.Cells.Add(cl);
    TestTable.Rows.Add(rw);
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion

    protected System.Web.UI.HtmlControls.HtmlTable TestTable;
    }



    Like I said, very simple.

    However, when I run the code, nothing shows up - I would expect to see a
    single cell with 'Test' displayed in it.

    Can anyone explain what's going on here?

    TIA,
    --
    Akin

    aknak at aksoto dot idps dot co dot uk
    Epetruk, Feb 11, 2005
    #1
    1. Advertising

  2. You're creating a new HTML Table, that could be causing the problem. The
    Table already exists that's part of the form so just create a local
    protected variable for the page class like so:

    protected HtmlTable TestTable;

    If this is being generated by VS.Net, it should already be creating a
    protected variable for you. Then all you do is add the row to the table just
    like you already do and it should be good. When you set the TestTable = new
    HtmlTable() in code behind you're now pointing TestTable to a different
    object, meaning it isn't referencing the one in the form anymore.

    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - FrontPage

    "Epetruk" <> wrote in message
    news:...
    > Hi all,
    >
    > I'm trying to write a simple page where a table's properties and contained
    > controls are generated dynamically.
    >
    > I have the following code:
    >
    >
    >
    > In Test.aspx:
    >
    > <%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false"
    > Inherits="Test.TestForm" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    > <HTML>
    > <HEAD>
    > <title>Test</title>
    > <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    > <meta content="C#" name="CODE_LANGUAGE">
    > <meta content="JavaScript" name="vs_defaultClientScript">
    > <meta content="http://schemas.microsoft.com/intellisense/ie5"
    > name="vs_targetSchema">
    > </HEAD>
    > <body MS_POSITIONING="GridLayout">
    > <form id="TestForm" method="post" runat="server">
    > <table id="TestTable" runat="server">
    > </table>
    > </form>
    > </body>
    > </HTML>
    >
    >
    >
    > In test.aspx.cs:
    >
    > public class TestForm : System.Web.UI.Page
    > {
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > // Put user code to initialize the page here
    > TestTable = new HtmlTable();
    > TestTable.Width = "100%";
    > HtmlTableRow rw = new HtmlTableRow();
    > HtmlTableCell cl = new HtmlTableCell();
    > cl.InnerText = "Test";
    > rw.Cells.Add(cl);
    > TestTable.Rows.Add(rw);
    > }
    >
    > #region Web Form Designer generated code
    > override protected void OnInit(EventArgs e)
    > {
    > //
    > // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    > //
    > InitializeComponent();
    > base.OnInit(e);
    > }
    >
    > /// <summary>
    > /// Required method for Designer support - do not modify
    > /// the contents of this method with the code editor.
    > /// </summary>
    > private void InitializeComponent()
    > {
    > this.Load += new System.EventHandler(this.Page_Load);
    > }
    > #endregion
    >
    > protected System.Web.UI.HtmlControls.HtmlTable TestTable;
    > }
    >
    >
    >
    > Like I said, very simple.
    >
    > However, when I run the code, nothing shows up - I would expect to see a
    > single cell with 'Test' displayed in it.
    >
    > Can anyone explain what's going on here?
    >
    > TIA,
    > --
    > Akin
    >
    > aknak at aksoto dot idps dot co dot uk
    >
    >
    Mark Fitzpatrick, Feb 11, 2005
    #2
    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,096
    Jacob Yang [MSFT]
    Aug 12, 2003
  2. Marty McDonald

    Dynamic table not showing

    Marty McDonald, Jan 30, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    359
    Marty McDonald
    Jan 30, 2004
  3. Epetruk

    Table not showing

    Epetruk, Feb 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    400
    Mark Fitzpatrick
    Feb 11, 2005
  4. Ray Booysen
    Replies:
    2
    Views:
    624
    Ray Booysen
    Mar 28, 2006
  5. SPG

    Pivot table not showing in Win XP?

    SPG, May 12, 2004, in forum: ASP General
    Replies:
    0
    Views:
    87
Loading...

Share This Page