Handling view state with Dynamic controls

G

Guest

1) I build a Html Table dynamically (Header Row, and then 2 rows with data
All 2 rows have 2 cells: cell(0) contains a delete button (ASP Button),
cell(1) contains a HTML Text box
2) On Form Load and get some data from a dataset and then from it's contents
build the page

At this point the page is rendered and 2 rows are displayed. There is an Add
button that a user can click to add another row to the table. This works fine
and the row is added.

Now if the user clicks the delete button in row 2 the form is posted back, I
rebuild the page, and then in the click event for the delete button remove
the row from the table and the dataset. All appears to be fine at this point.

Now if the user clicks the add button again another row is added, but this
time row 2's textbox has the wrong value. It appears to be related to the
view state. I think the view state somehow is not getting cleared when the
row is removed.

Any help would be appreciated
 
G

Guest

I'm not sure what you mean. When the user clicks the delete row button:
1) postback to the page
2) rebuild the page(including the row that was deleted
3) delete the row from the table
4) update the dataset from which I deleted the table
5) Update the contents of the table

As of now, all of the above is done during form load.

Thanks for help!
 
G

Guest

Shouldn't your code to delete the row from your dataset be in the
DeleteButton_Clicked event?

My way of doing it would be (pseudo code):

sub page_load
if not(ispostback()) then
createdataset 'create dataset from datasource
savedataset 'put a copy of the dataset into the view state
else
loaddataset 'reload the dataset from the viewstate
end if
end sub

sub addButton_Clicked
addRow 'add row to dataset
savedataset 'update the viewstate with the updated dataset
end sub

sub deleteButton_Clicked
delRow 'remove the row from the dataset
savedataset 'update the viewstate with the updated dataset
end sub

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top