Dynamic Tables / Unable to clear content

G

g2

I am adding rows dynamiclly to a table in the postback. In my second
postback the contents of the table are not getting updated i.e. the contents
are always from the first postback. Any ideas why this is happening?
Thanks.
 
Y

Yan-Hong Huang[MSFT]

Hello,

Programmatically created controls need to be recreated on each postback. Each time your page is called, it recreates itself
from scratch based on the contents of aspx page and then applies viewstate to those controls. The controls (table rows and
cells) which were created during a previous postback no longer exist and so viewstate cannot be applied to them. What you
need to do is save the entire state of your table, in a Session variable for example, and then completely recreate the table
on each postback.

For an example, if you add one row data when editing property of table control in IDE. You could see this line of row always.
However, if you add the following code in Page_load,
if ( Page.IsPostBack )
{
TableRow tRow = new TableRow();
TableCell tCell1 = new TableCell();
tCell1.Text = "cell1";
tRow.Cells.Add(tCell1);
TableCell tCell2 = new TableCell();
tCell2.Text = "cell2";
tRow.Cells.Add(tCell2);
TableCell tCell3 = new TableCell();
tCell3.Text = "cell3";
tRow.Cells.Add(tCell3);
Table1.Rows.Add(tRow);
}
Each time, only one line of suce row appears.

For details, please refer to http://msdn.microsoft.com/library/en-
us/vbcon/html/vbtskaddingcontrolstowebformspageprogrammatically.asp?frame=true for details.

Hope it helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "g2" <[email protected]>
!Subject: Dynamic Tables / Unable to clear content
!Date: Mon, 4 Aug 2003 23:13:39 -0400
!Lines: 6
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <e7eZT#[email protected]>
!Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
!NNTP-Posting-Host: dhcp-0-a0-cc-e1-8-3a.cpe.townisp.com 216.195.29.171
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:13677
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
!
!I am adding rows dynamiclly to a table in the postback. In my second
!postback the contents of the table are not getting updated i.e. the contents
!are always from the first postback. Any ideas why this is happening?
!Thanks.
!
!
!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,174
Latest member
BlissKetoACV
Top