Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

dynamic table viewstate problem

Avatar of cacliffo
cacliffoFlag for United States of America asked on
C#ASP.NET
3 Comments1 Solution626 ViewsLast Modified:
Hello,

I have a table who's rows I need to populate dynamically based on the values selected in several drop down lists.

I have been calling the function to populate this table from Page_Load (since it depends on the values of other controls who's viewstate and postback data will not be loaded until Page_Load), like this:

        protected void Page_Load(object sender, EventArgs e)
        {
            populateQueueTable();
        }

This was working fine, until I tried to add sorting like this:
        protected void btnSort_Click(object sender, EventArgs e)
        {
            if (sender == btnDate)
            {
                hfSortType.Value = "1";
            }

            if (sender == btnAuthor)
            {
                hfSortType.Value = "2";
            }

            if (sender == btnFilename)
            {
                hfSortType.Value = "3";
            }

           
            while (tableQueue.Rows.Count > 1)
            {
                tableQueue.Rows.RemoveAt(1);
            }

            populateQueueTable();
           
        }

The problem is that on the first postback after the table is sorted (not including the postbock where the sort happens), the controls in my dynamic table lose their view state. After that postback, it works fine again.

It seems to me that there shouldn't be any problems loading view state because I am creating the same control hierarchy on every postback in Page_Load.

What is the problem here and how can I fix it?

Thanks,
Nick
ASKER CERTIFIED SOLUTION
Avatar of cacliffo
cacliffoFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers