1
votes

I've got an update panel with a repeater and some fields. When a user fills out the details on the fields it populates a collection I keep in the Viewstate which is then bound to the repeater.

So the updatepanel updates and the repeater now contains the new item the values for which the user just filled out in the form.

I've also got an edit button as part of that repeater which, when clicked, populates the form fields with the data the user initially entered.

What I want to do then is for the user to be able to edit this data and 'save' the item, but instead of it being added to the collection / viewstate it edits whatever item the user had chosen and updates the collection / viewstate to reflect that.

For example, imagine a form with two fields:

Name: Age:

I enter Bob and 46 and hit save.

Repeater now shows an entry for Bob 46 with an 'edit' button beside it. User clicks on the edit button and the form fields are populated with Bob and 46 again.

User then changes it to Bob Age 47 and hits save. Now instead of there then being two entries (Bob 46 and Bob 47) - the bob 46 one would be updated to Bob 47.

Hope this is clear, It's a little obscure but I think I've explained the gist of it. Important thing to remember is that this is all happening in the update panel so I'm using Viewstate to contain the collection that populates the repeater.

1

1 Answers

0
votes

Your question indicates a bit of confusion about how ASP.NET's UpdatePanel works.

Anytime you do a "partial" postback to update your UpdatePanel, your page actually executes in full, going through all parts of the page lifecycle regardless of their relevance to your UpdatePanel. Then, just the UpdatePanel refreshes on the page. This behavior gives the appearance of the page working more quickly, and I suppose it could save some rendering time on the client side, but really, you are doing a full postback every time you refresh the UpdatePanel.

With that in mind, if you are going to use an UpdatePanel to hold your repeater, there is no reason to do anything terribly special to hold the data. Just use the normal repeater methods to add, edit, etc. Unless there is another requirement that I'm missing here, there is no particular reason to store the data in ViewState any more than the ASP.NET controls already do. You would have to ensure that anything that you wish to trigger an update of the UpdatePanel does so, but you're not indicating any confusion about that.