Thanks for Marina's input.
Hi David,
If you have any further question, please feel free to post here.
Regards,
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" <so*****@nospam.com>
| References: <3F**********************************@microsoft.co m>
<u#*************@tk2msftngp13.phx.gbl>
<q$**************@TK2MSFTNGXA02.phx.gbl>
<AA**********************************@microsoft.co m>
| Subject: Re: nullreferenceexception for Private Object Variables
| Date: Wed, 14 Dec 2005 09:16:08 -0500
| Lines: 127
| 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: <er**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: gw.deltek.com 63.72.155.97
| Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSF TNGXA01.phx.gbl!TK2MSFTNGP
08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:364752
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| In process session state can store the object as is in memory, no
| serialization. View State serializes the object.
|
| "David Whitchurch-Bennett" <Da******@nospam.nospam> wrote in message
| news:AA**********************************@microsof t.com...
| > 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" <so*****@nospam.com>
| >> | References: <3F**********************************@microsoft.co m>
| >> | 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#*************@tk2msftngp13.phx.gbl>
| >> | Newsgroups: microsoft.public.dotnet.framework.aspnet
| >> | NNTP-Posting-Host: gw.deltek.com 63.72.155.97
| >> | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.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" <Da******@nospam.nospam> wrote in message
| >> | news:3F**********************************@microsof t.com...
| >> | > 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?
| >> |
| >> |
| >> |
| >>
| >>
|
|
|