Variables and ASP.NET

Hi all!!!

    I need to add a new user to my ASP.NET application. This process is done filling three Forms (UserControls). When i validate the first form, I create a new object CadUser, that stores all user information and roles that is being filled by the forms.

    Suppose that i ended filling my first form. So, i click on my NextStep button. When I Click on it, a new CadUser object is created (It is created as as "Class Level" object, not as "Method Level") and i redirected to the 2nd form. So, i fill the 2nd form. When i will store the information filled on the 2nd form, i try to get a reference to the CadUser obj created before, and it is not there... (CadUser = Nothing)

    So, i need to know how i could store objects that will be read after a page postback and how could i dispose the resources used by this object when i don't need to use it anymore.

Thanks.
regisdanielAsked:
Who is Participating?
 
HavaganConnect With a Mentor Commented:
ASP.NET pages are stateless so you need to use one of the methods of maintaining state: Session, ViewState, Cache. Session is specific to your user and lasts across pages -- it is disposed of when the user's Session ends (i.e. they close the browser, etc.), ViewState is specific to your user and lasts for the life of a page (when the user leaves the one page the ViewState is gone) and is stored in a hidden field in your page code which increases the page's download size, Cache is global to your application (so if user1 creates an object with cache name "NewUser" and user 2 creates an object with cache name "NewUser", user 1's object is gone and he will access user 2's object) and is disposed of based upon an expiration date you set or you can manually dispose of cached objects.

If you're using a lightweight class (like a user with just a name/basic information in it) I would use Session to store the information between pages or ViewState if you're only dealing with one page and postbacks.

Paul
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.