Self-refreshing and non-self-refreshing controls

Discussion in 'ASP .Net Web Controls' started by Harlan Messinger, Aug 3, 2006.

  1. 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?
     
    Harlan Messinger, Aug 3, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    584
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    598
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    404
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    379
    falcon
    Jul 31, 2005
  5. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    460
    =?Utf-8?B?Y2xpY2tvbg==?=
    Aug 4, 2006
Loading...

Share This Page