0

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!

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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
0

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.

3 Comments

You'd be surprised how sometimes stating the obvious helps to get someone unstuck.
ocdecio the "be nice" comment was aimed at Will. No point scaring the new guys away with sarcasm :)
@Eoin - well said. We've all been there one day,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.