views:

66

answers:

2

Hi,

Let's say I have a class Person, with a string[] nickNames, where Person can have 0 or more nicknames stored. I want to create an asp.net page where a user can go and add/edit/delete nicknames.
Question is- how to i persist the Person object between postbacks? I query the DB and create the object then display it on a form, but then the user has the option to edit/delete fields of that object.. once the page is displayed with the fields of Person, how do I update that object with the changes the user made, to store to db?

Thanks!

A: 

Query the object it again (you could store it in a session variable but that doesn't scale), gather and apply changes from user upon postback.

Otávio Décio
I'm guessing he probably won't have to worry about scaling on his project...
Will
now now. be nice :)
Eoin Campbell
You'd be surprised how sometimes stating the obvious helps to get someone unstuck.
Otávio Décio
ocdecio the "be nice" comment was aimed at Will. No point scaring the new guys away with sarcasm :)
Eoin Campbell
@Eoin - well said. We've all been there one day,
Otávio Décio
+1  A: 

Well if your Person Object is serializable you could store it in ViewState and if not, you could stick it in Session, but it sounds like you might have a general lack of understanding about Data Persistance in general

Depending on your implementation, and whether you're coding this all by hand or using the built in DataSource/DataAdapter controls, theres a bunch of ways to do it.

You could have a look at some basic ASP.NET/ADO.NET Tutorials to point you in the right direction

http://aspnet101.com/aspnet101/tutorials.aspx?id=17

Eoin Campbell
hmm, so if the Person object expands to typical contact information- address, name, etc., maybe 20 fields.. would it be preferable to serialize the object and store in ViewState, or to put it in Session?I will be using the built in SQL data source / adapter controls and have looked into databinding but since this is not being displayed in a gridview, and also since they will be able to add additional nicknames, i don't think I can use databinding