Re: nullreferenceexception for Private Object Variables
- From: David Whitchurch-Bennett <DavidRWB@xxxxxxxxxxxxx>
- Date: Wed, 14 Dec 2005 08:22:02 -0800
Oh that's great! Thanks a lot for you help, and will read all about session
states now!
David.
"David Whitchurch-Bennett" wrote:
> 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?
> > |
> > |
> > |
> >
> >
.
- 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: pass null values
- Next by Date: Re: Help on validation process?
- Previous by thread: Re: nullreferenceexception for Private Object Variables
- Next by thread: Enterprise application blocks for .net 2.0
- Index(es):
Relevant Pages
|