Re: nullreferenceexception for Private Object Variables
- From: "Marina" <someone@xxxxxxxxxx>
- Date: Wed, 14 Dec 2005 09:16:08 -0500
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?
>> |
>> |
>> |
>>
>>
.
- Follow-Ups:
- Re: nullreferenceexception for Private Object Variables
- From: Steven Cheng[MSFT]
- Re: nullreferenceexception for Private Object Variables
- References:
- Re: nullreferenceexception for Private Object Variables
- From: Marina
- Re: nullreferenceexception for Private Object Variables
- From: Steven Cheng[MSFT]
- Re: nullreferenceexception for Private Object Variables
- From: David Whitchurch-Bennett
- Re: nullreferenceexception for Private Object Variables
- Prev by Date: Re: File download
- Next by Date: Re: Code blocks are not supported in this context
- Previous by thread: Re: nullreferenceexception for Private Object Variables
- Next by thread: Re: nullreferenceexception for Private Object Variables
- Index(es):
Relevant Pages
|