ASP.NET question

PricklyPete

Lifer
Sep 17, 2002
14,582
162
106
Using .NET 1.1, I did the following:

Created a Web Control Table and dynamically added some text/controls to several rows using the attached code.

I've also added a button that merely submits the page back to the server and then writes out a value to a label.

When the page loads, the table comes up as expected. When I click the button, the page returns with the value written to the label, but my table is gone (well the rows of data are).

The tables "EnableViewState was set to true, so why did it not re-appear? I specifically put in the "isPostBack ==false" condition so that the database would not be accessed multiple times thinking the state of the page would be maintained...but I'm missing something here. I haven't done any ASP.NET programming in a while and I've gotten even rustier than I was.

Thanks for any help.


 

rsd

Platinum Member
Dec 30, 2003
2,293
0
76
Just quickly glancing at it, even though you have enableviewstate set to true, you still need to store this in viewstate (or sessionstate). It isn't like a gridview because you are creating this table dynamically in the code-behind. Try actually saving it in viewstate (and then simply loading it from viewstate if it exists there).
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
I think rsd has it right--ViewState preserves only the state that each web control wants to preserve between calls. Since you're creating these controls dynamically, they don't have a chance to restore their viewstate when the page loads again since they aren't even created on the page.