Self-refreshing and non-self-refreshing controls

Discussion in 'ASP .Net' started by Harlan Messinger, Aug 4, 2006.

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

  2. 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?
    >
    =?Utf-8?B?Y2xpY2tvbg==?=, Aug 4, 2006
    #2
    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:
    561
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    580
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    390
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    360
    falcon
    Jul 31, 2005
  5. Harlan Messinger

    Self-refreshing and non-self-refreshing controls

    Harlan Messinger, Aug 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    180
    Harlan Messinger
    Aug 3, 2006
Loading...

Share This Page