473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Table not showing

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
Nov 19 '05 #1
1 1341
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" <no****@blackhole.com> wrote in message
news:37*************@individual.net...
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bajal Mohamed via SQLMonster.com | last post by:
I am facing problem like; We generate reports thru Excel Pivot table. The data is coming from sales cube. Let?s assume that there are 2 products A and B. The user wants to filter for each...
2
by: db2group88 | last post by:
hi, we install db2 udb v8.1 on windows 64bit, in our application, we have sql execute "create table .... not logged initially", but from the operating system event viewer showing error stating that...
2
by: Emily Jones | last post by:
That subject line will have Joe Celko apoplectic!! Let's say I have this thing. Oh, I don't know, a car. No, a vehicle. Can we agree that is an entity type? Some attributes might be VIN, Fuel,...
2
by: Raed Sawalha | last post by:
I have the following table in ascx , when I click the button the table style not showing in the popup , it is ONLY showing on the page not in the popup...WHY? <TABLE style="BACKGROUND:...
2
by: ezmiller | last post by:
Hi, I have some code (which I will paste in below) that writes out some HTML dynamically using the W3C DOM...the last part of the code write out a simple table. MY problem is that the table is...
1
by: Rahul | last post by:
Hi, I tried many option, but did not found solution. Same Validation Error showing. If I have convert one table, it can easily converted. But If I have paste another table in same file, then...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
2
by: spacix | last post by:
Does anyone know a work around for "table-layout: fixed;" to prevent the automatic evenly space cells width without assigning classes or ID to cells? My program prints a HTML "report" file and I...
5
by: sitko | last post by:
Hi, I'm done a little HTML here and there over the years...but nothing professionally. Now I'm working on a project which calls for some simple HTML. Here is my markup, for the life of me I can't...
3
by: reelrave | last post by:
Hello All, I've checked around a little on Google (and this group) and have found info similar to what I'm trying to do (i.e., changes that were made in the BE's tables are not reflected in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.