By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,841 Members | 854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,841 IT Pros & Developers. It's quick & easy.

Self-refreshing and non-self-refreshing controls

P: n/a
[sorry for the multipost but I got no response in m.p.d.f.a.webcontrols]

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?
Aug 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In my experience ASP table controlls are just wierd and behave eratically,
have you found this behavour for anything other than a table control

"Harlan Messinger" wrote:
[sorry for the multipost but I got no response in m.p.d.f.a.webcontrols]

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?
Aug 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.