Table Ignores EnableViewState

Discussion in 'ASP .Net' started by Jonathan Wood, Jan 27, 2008.

  1. I have a table that I dynamically populate by creating cells and rows. The
    data comes from a database so I would prefer to have the table store the
    data in its viewstate rather than having to repopulate it on every postback.

    But it doesn't work. I ensure the table's EnableViewState is true. But
    whenever there's a postback and I don't repopulate the table, it disappears.
    I'm thinking this has something to do with my dynamic data not being stored
    in the table's viewstate. But I'm not sure why or what the best workaround
    is.

    Any tips?

    Thanks.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com
    Jonathan Wood, Jan 27, 2008
    #1
    1. Advertising

  2. Jonathan Wood

    Guest

    On 27 ÑÎ×, 22:46, "Jonathan Wood" <> wrote:
    > I have a table that I dynamically populate by creating cells and rows. The
    > data comes from a database so I would prefer to have the table store the
    > data in its viewstate rather than having to repopulate it on every postback.
    >
    > But it doesn't work. I ensure the table's EnableViewState is true. But
    > whenever there's a postback and I don't repopulate the table, it disappears.
    > I'm thinking this has something to do with my dynamic data not being stored
    > in the table's viewstate. But I'm not sure why or what the best workaround
    > is.
    >
    > Any tips?
    >
    > Thanks.
    >
    > --
    > Jonathan Wood
    > SoftCircuits Programminghttp://www.softcircuits.com


    Hi Jonathan,

    One option would be to create cells and rows in page's
    CreateChildControls method (you might
    store number of rows and cells in page's ViewState, so you can
    recreate exactly the same number of rows/cells on postback),
    So as soon as you create them in CreateChildControls they will be
    recreated on postback and will grab all properties
    you have assigned to them initially from ViewState.
    You might also need to call EnsureChildControls before you assign/read
    cell properties (in Page_Load or smth.).


    Thanks,
    Sergey Zyuzin
    , Jan 27, 2008
    #2
    1. Advertising

  3. "Jonathan Wood" <> wrote in message
    news:%...

    >I have a table that I dynamically populate by creating cells and rows. The
    >data comes from a database so I would prefer to have the table store the
    >data in its viewstate rather than having to repopulate it on every
    >postback.
    >
    > But it doesn't work. I ensure the table's EnableViewState is true. But
    > whenever there's a postback and I don't repopulate the table, it
    > disappears. I'm thinking this has something to do with my dynamic data not
    > being stored in the table's viewstate.


    It's not your dynamic data as such - it's that dynamically added controls
    (in this case, <tr> and <td>) don't survive a postback, and need to be
    recreated every time the page loads...

    > Any tips?


    Use a GridView...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Jan 28, 2008
    #3
    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. Dave Verwer

    EnableViewState = false not working

    Dave Verwer, Jul 10, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    684
    Dave Verwer
    Jul 10, 2003
  2. Ravikanth[MVP]
    Replies:
    1
    Views:
    1,734
    Christian H
    Jul 24, 2003
  3. sultan zahir khan
    Replies:
    2
    Views:
    445
    Joao S Cardoso [MVP]
    Jul 24, 2003
  4. AFN
    Replies:
    6
    Views:
    4,360
  5. Andrey Tarasevich

    IE ignores table cell height propery - why?

    Andrey Tarasevich, Aug 8, 2005, in forum: HTML
    Replies:
    6
    Views:
    30,045
    mbstevens
    Aug 9, 2005
Loading...

Share This Page