Variables and ASP.NET

Posted on 2005-04-13
Last Modified: 2010-04-07
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.

Question by:regisdaniel
    1 Comment
    LVL 6

    Accepted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now