Self-refreshing and non-self-refreshing controls

  • Thread starter Harlan Messinger
  • Start date
H

Harlan Messinger

If I have a dropdown list ddl, and the following code appears in
Page_Load, then on each postback the rows previously added persist and I
wind up with more and more copies of the same rows. To avoid this, I
have to wrap the lines in an if (!Page.IsPostBack) block.

ddl.Items.Add("One");
ddl.Items.Add("Two");
ddl.Items.Add("Three");

But if I have a table control Table1 and do the same thing, the table
starts from scratch upon postback, so only the rows currently being
added appear in the table. Therefore, this code doesn't go in an if
(!Page.IsPostBack) block.

string[] keys = Request.Headers.AllKeys;
foreach (string key in keys)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Text = key;
row.Cells.Add(cell);
cell = new TableCell();
cell.Text = Request.Headers[key];
row.Cells.Add(cell);
Table1.Rows.Add(row);
}


Both the dropdown list control and the table control have
EnableViewState=true. So why the difference in behavior? For any given
control, how do I know which behavior to expect?
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top