Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Table not showing

Reply
Thread Tools

Table not showing

 
 
Epetruk
Guest
Posts: n/a
 
      02-11-2005
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


 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      02-11-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sh Crypto isakmp sa is showing Active but Tunnel is showing line protocol down. urvin Cisco 0 04-15-2008 08:17 AM
ASP 1.1: DataGrid - Showing/Not Showing Buttons Ray Booysen ASP .Net 2 03-28-2006 02:49 PM
Table background colours not showing up in Firefox Big Craigie Firefox 1 04-04-2005 11:49 PM
Device not showing in cam table but is connected and pingable. Matt P. Cisco 2 11-10-2004 10:55 AM
Could not load type VTFixup Table from assembly Invalid token in v-table fix-up table. David Williams ASP .Net 2 08-12-2003 07:55 AM



Advertisments