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?
LVL 1
macros14Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

strickddCommented:
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
}
0
aki4uCommented:
In your Page_Load Event write(first line in this sub):

C#:
if (Page.IsPostBack)
      return;

VB.NET:
If (Page.IsPostBack) Then Exit Sub
0
macros14Author Commented:
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?
0
strickddCommented:
If you dynamically create content in .Net you have to keep populating that information on postback or else it will default to whatever the control is set up to be. Another option you have it to set the table into a session object:

private void Page_Load(object sender, System.EventArgs e)
{
      if( !Page.IsPostback)
      {
          FillTable();
      }

     if(Page.IsPostback)
     {
         ShowTable();
     }
}


private void FillTable()
{
     Session["TableData"] = tableObj;
}

private void ShowTable()
{
     tableObj = (Table)Session["TableData"]; //This will cast the session as object type Table
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.