Link to home
Create AccountLog in
Avatar of macros14
macros14

asked on

asp:table loses data

I have a asp:table that I put on my aspx page.  I then on page_load create some rows for it.  Everything works fine and the table displays, but I do other processing on the page where I need to postback, so when I hit a button to postback, the table is gone, even though I have enableviewstate set to true.  Is there a way to display the table so I don't have to recreate it on every postback?
Avatar of strickdd
strickdd
Flag of United States of America image

Create a function that creates the table and then call it regardless of page postback

private void Page_Load(object sender, System.EventArgs e)
{
      FillTable(); //must be outside of !Page.IsPostback so it fires each time

      if( !Page.IsPostback)
      {
          //do whatever
      }
}


private void FillTable()
{
     //code to create table
}
Avatar of aki4u
aki4u

In your Page_Load Event write(first line in this sub):

C#:
if (Page.IsPostBack)
      return;

VB.NET:
If (Page.IsPostBack) Then Exit Sub
Avatar of macros14

ASKER

I don't want to create the table everytime on postback, it takes awhile to process, is there a reason why enableviewstate isn't working with the table?
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer