Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding rows to a "asp:Table" based on a button click - But rows gone!

Status
Not open for further replies.

KidHoss

Programmer
May 22, 2000
27
US
I am creating a data entry form to allow the user to create bullet items and sub bullet items for storage in a SQL Server table. These items are stored in the database with codes denoting whether the item is a bullet point or a sub-bullet point. This data is used to create a dynamic ASP.Net page. The data is read and constructed into unordered lists on the output web pages.

To allow the users to enter these bullet points in a method where they would resemble what they would look like in a list, I build a two column "asp:table" with text boxes inserted in each cell. I provide a button for the user to add rows if they need to add more bullet points.

HOWEVER ..... when the button is clicked, the row is added to the table but a row previously is lost. I know this is VIEWSTATE management problem. The table is not being set as being "dirty" in the viewstate. I believe I need to do that within the button click event that is adding rows to the table.

HOWEVER ..... I cannot figure out how to do this. I have been reading about state mangement and I have been reading about serialization of objects (because that is one of the errors I get when I try to add the table object to the state).

Does anyone have a chunk of code in VB that shows how to add a table to the viewstate or the StateBag (whichever it is that I am supposed to use)? I think if I see a piece of code showing how to save and restore the state of a table object I will get it. Am I wrong in my assumption that I need to save the state of the table after I add a row and restore the state of the table on the next post back?

I appreciate anyone who can help me out with this.
 
ViewState just stores the Values of a server control and NOT the control itself.

when createing dynamic .NET controls u have to be very carefll as they are lost in postback. search around this forum, there are a couple of excellent threads regarding this...

Known is handfull, Unknown is worldfull
 
When adding controls dynamically, add them in the Page_init event, not the Page_load event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top