Re: nullreferenceexception for Private Object Variables

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



In process session state can store the object as is in memory, no
serialization. View State serializes the object.

"David Whitchurch-Bennett" <DavidRWB@xxxxxxxxxxxxx> wrote in message
news:AA1DF3F4-2C9E-4391-AA59-AA94F17C1082@xxxxxxxxxxxxxxxx
> Thank you both for replying to the question.
>
> The trouble is, the object is not serializable, and is actually an object
> which needs to be logged into, and a number of methods performed before
> access to the properties is granted. Does Viewstates and SessionStates
> actually store objects themselves, or just XML representations of them?
>
> Thanks again,
>
> David
>
> "Steven Cheng[MSFT]" wrote:
>
>> Hi David,
>>
>> I agree with Marina on this. Since the ASP.NET web page is based on HTTp
>> which is stateless, so the page object model (instance member values....)
>> will not be persisted between multiple requests ( postback...). Generally
>> for mantaining states between multiple requests, we need to store those
>> variables in some persistent store such as SessionState or
>> ViewState......
>>
>> for example:
>>
>> using ViewState.....
>>
>> Public Property anObject() As Object
>> Get
>> Return ViewState("myobject")
>> End Get
>> Set(ByVal value As Object)
>> ViewState("myobject") = value
>> End Set
>> End Property
>>
>>
>> Hope helps. Thanks,
>>
>> Steven Cheng
>> Microsoft Online Support
>>
>> Get Secure! www.microsoft.com/security
>> (This posting is provided "AS IS", with no warranties, and confers no
>> rights.)
>>
>>
>>
>>
>>
>> --------------------
>> | From: "Marina" <someone@xxxxxxxxxx>
>> | References: <3F629843-A182-4705-BD60-A7E8FDA37461@xxxxxxxxxxxxx>
>> | Subject: Re: nullreferenceexception for Private Object Variables
>> | Date: Tue, 13 Dec 2005 11:38:48 -0500
>> | Lines: 42
>> | X-Priority: 3
>> | X-MSMail-Priority: Normal
>> | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
>> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
>> | X-RFC2646: Format=Flowed; Original
>> | Message-ID: <u#rwyOAAGHA.984@xxxxxxxxxxxxxxxxxxxx>
>> | Newsgroups: microsoft.public.dotnet.framework.aspnet
>> | NNTP-Posting-Host: gw.deltek.com 63.72.155.97
>> | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
>> | Xref: TK2MSFTNGXA02.phx.gbl
>> microsoft.public.dotnet.framework.aspnet:364526
>> | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>> |
>> | HTTP is a stateless protocol. A new instance of the page object is
>> created
>> | on every request. So on a postback, you get a brand new instance of the
>> page
>> | and everything else on it. That object on which you set the property
>> before
>> | no longer exists.
>> |
>> | "David Whitchurch-Bennett" <DavidRWB@xxxxxxxxxxxxx> wrote in message
>> | news:3F629843-A182-4705-BD60-A7E8FDA37461@xxxxxxxxxxxxxxxx
>> | > Hi There,
>> | >
>> | > I have created a very simple web user control, containing only a
>> combo
>> | > box.
>> | > I have created a class which contains some private object variables,
>> for
>> | > example...
>> | >
>> | > Private _anObject as Object
>> | >
>> | > Public Property anObject() As Object
>> | > Get
>> | > Return _anObject
>> | > End Get
>> | > Set(ByVal value As Object)
>> | > _anObject = value
>> | > End Set
>> | > End Property
>> | >
>> | > I set the AnObject object from the main ASP form, and the local
>> private
>> | > _anObject object is set correctly.
>> | >
>> | > If I want to refer to this private _anObject object later, when the
>> user
>> | > clicks on a combo box item, I get a NULLREFERENCEEXCEPTION, and the
>> | > private
>> | > object is back to nothing again.
>> | >
>> | > Protected Sub ComboClick(ByVal sender As Object, ByVal e As
>> | > System.EventArgs) Handles Combo1.SelectedIndexChanged
>> | > dim myNewObject as Object=_anObject
>> | > End Sub
>> | >
>> | > Why is the happening, and what is the correct way to store objects in
>> | > classes in ASP.NET?
>> |
>> |
>> |
>>
>>


.



Relevant Pages

  • Re: State Management
    ... serialization. ... or Out-Of-Process session state as these session storage methods ... temporarily store state. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Storing objects in Session variables
    ... "If you are using InProc mode, objects stored in session state are ... and so you can store whatever object you have ... framework serialization functionality or through any other serialization ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Storing a datatable (or arraylist )on ASP.NET Session
    ... Perhaps your ArrayList store smth which can't be casted to object. ... If exactly that code u shown didn't work (emply arraylists) that I recomment to re-register asp.net 2.0 calling aspnet_regiis,exe - i ... Team blog: http://devkids.blogspot.com/ ... b> session variables is stored on web server's local sql database. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: LISP for web
    ... >>Ideas on how to store this information centrally for all of the app ... > ucw's form handling code (to make sure session ids are always ... > can deal with hardware failures an the app servers but this ...
    (comp.lang.lisp)
  • Re: Problem with asp.net app only allowing 1 user at a time
    ... from the client to the server), Application (an object that can store ... Now in your case you are reading and writing everything to the database, ... there is the Session object. ... To retrieve this you would do something like: ...
    (microsoft.public.dotnet.framework.aspnet)