473,765 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IStateManager in a class object

I am creating a class (not a control) which implements IStateManager. I've
created the class and all of the implementations (LoadView, SaveViewState,
etc...). My Question is: How do I instantiate this class in a page and
then re-instantiate it on post back such that I don't lose it's viewstate?
If the page always uses x = new myclass to instantiate, the myclass
constructor is always going to reinitialize its statebag.


Nov 19 '05 #1
6 1279
This approach is typically done when a control (or the page) needs to use
a helper object to track the viewstate. So the usage model is for the control
to instantiate an instance of the helper object and then override all of
the IStateManager APIs and call into the helper object for each one (so override
LoadViewState and the call into the helper's LoadViewState, etc...). This
is how the helper object gets 'hooked into' the page model. I hope that just
made sense :)

-Brock
DevelopMentor
http://staff.develop.com/ballen
I am creating a class (not a control) which implements IStateManager.
I've created the class and all of the implementations (LoadView,
SaveViewState, etc...). My Question is: How do I instantiate this
class in a page and then re-instantiate it on post back such that I
don't lose it's viewstate? If the page always uses x = new myclass to
instantiate, the myclass constructor is always going to reinitialize
its statebag.

Nov 19 '05 #2
Thanks for the reply....but you lost me there. If I'm using this in a page
I understand about overriding the pages LoadViewState, SaveViewState.. .and
calling the helper class LoadViewState, etc... The paradox I'm lost on is
how the instance of the helper is saved and reinstantiated such that the
value in it's statebag persist. The page needs to instantiate the helper
somewhere. And if the helper has a constructor which instantiates the
statebag, the statebag (and thus the viewstate) is going to be empty.


"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:b8******** *************** ***@msnews.micr osoft.com...
This approach is typically done when a control (or the page) needs to use
a helper object to track the viewstate. So the usage model is for the
control
to instantiate an instance of the helper object and then override all of
the IStateManager APIs and call into the helper object for each one (so
override
LoadViewState and the call into the helper's LoadViewState, etc...). This
is how the helper object gets 'hooked into' the page model. I hope that just
made sense :)

-Brock
DevelopMentor
http://staff.develop.com/ballen
I am creating a class (not a control) which implements IStateManager.
I've created the class and all of the implementations (LoadView,
SaveViewState, etc...). My Question is: How do I instantiate this
class in a page and then re-instantiate it on post back such that I
don't lose it's viewstate? If the page always uses x = new myclass to
instantiate, the myclass constructor is always going to reinitialize
its statebag.


Nov 19 '05 #3
Right, so you'll create the helper and it will be empty until LoadViewState
is called. That's why it's important to forward the overrides to the helper.
So, yes, ViewState won't be loaded until the Page base class calls the LoadViewState
virtual.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Thanks for the reply....but you lost me there. If I'm using this in a
page I understand about overriding the pages LoadViewState,
SaveViewState.. .and calling the helper class LoadViewState, etc...
The paradox I'm lost on is how the instance of the helper is saved and
reinstantiated such that the value in it's statebag persist. The page
needs to instantiate the helper somewhere. And if the helper has a
constructor which instantiates the statebag, the statebag (and thus
the viewstate) is going to be empty.

"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:b8******** *************** ***@msnews.micr osoft.com...
This approach is typically done when a control (or the page) needs to
use
a helper object to track the viewstate. So the usage model is for the
control
to instantiate an instance of the helper object and then override all
of
the IStateManager APIs and call into the helper object for each one
(so
override
LoadViewState and the call into the helper's LoadViewState, etc...).
This
is how the helper object gets 'hooked into' the page model. I hope
that just
made sense :)
-Brock
DevelopMentor
http://staff.develop.com/ballen
I am creating a class (not a control) which implements IStateManager.
I've created the class and all of the implementations (LoadView,
SaveViewState, etc...). My Question is: How do I instantiate this
class in a page and then re-instantiate it on post back such that I
don't lose it's viewstate? If the page always uses x = new myclass
to instantiate, the myclass constructor is always going to
reinitialize its statebag.

Nov 19 '05 #4
Hi Brad,

My understanding on your question is that you want your custom component
class be able to automatically be able to utilize the asp.net page's state
management, (e.g. persist and load states into/from viewstate).
If so, I'm afraid a normal class can not automatically hook into these
process/ events model since the ASP.NET page doesn't know that it need to
call your custom class's certain state mangement api. To achieve this, we
need to override page class's LoadViewState/SaveViewState funciton or hook
into the Init ,Load, event so as to construct and populate your custom
class's instance on the page. However I don't think this is possible for a
common component class.

So the option left to us is just derive our class from the
System.Web.UI.C ontrol, and when used on page, it is added into the asp.net
page's control collection. So that ASP.NET page will know that it need to
call your object(control) 's state management methods at the proper time.
Actually we can find some realworld examples like the DataSource controls
in asp.net 2.0, though they're only utility components which haven't UI
related task, they're still designed as Control since they need to hook
into the asp.net page's runtime event model and state management steps.

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.)


--------------------
| Message-ID: <b8************ **************@ msnews.microsof t.com>
| From: Brock Allen <ba****@NOSPAMd evelop.com>
| Subject: Re: IStateManager in a class object
| References: <Op************ **@TK2MSFTNGP09 .phx.gbl>
| MIME-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 671.6
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Date: Thu, 29 Sep 2005 14:55:26 -0700
| NNTP-Posting-Host: host81-153-126-137.range81-153.btcentralpl us.com
81.153.126.137
| Lines: 1
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1281 15
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Right, so you'll create the helper and it will be empty until
LoadViewState
| is called. That's why it's important to forward the overrides to the
helper.
| So, yes, ViewState won't be loaded until the Page base class calls the
LoadViewState
| virtual.
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen
|
| > Thanks for the reply....but you lost me there. If I'm using this in a
| > page I understand about overriding the pages LoadViewState,
| > SaveViewState.. .and calling the helper class LoadViewState, etc...
| > The paradox I'm lost on is how the instance of the helper is saved and
| > reinstantiated such that the value in it's statebag persist. The page
| > needs to instantiate the helper somewhere. And if the helper has a
| > constructor which instantiates the statebag, the statebag (and thus
| > the viewstate) is going to be empty.
| >
| > "Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
| > news:b8******** *************** ***@msnews.micr osoft.com...
| > This approach is typically done when a control (or the page) needs to
| > use
| > a helper object to track the viewstate. So the usage model is for the
| > control
| > to instantiate an instance of the helper object and then override all
| > of
| > the IStateManager APIs and call into the helper object for each one
| > (so
| > override
| > LoadViewState and the call into the helper's LoadViewState, etc...).
| > This
| > is how the helper object gets 'hooked into' the page model. I hope
| > that just
| > made sense :)
| > -Brock
| > DevelopMentor
| > http://staff.develop.com/ballen
| >> I am creating a class (not a control) which implements IStateManager.
| >> I've created the class and all of the implementations (LoadView,
| >> SaveViewState, etc...). My Question is: How do I instantiate this
| >> class in a page and then re-instantiate it on post back such that I
| >> don't lose it's viewstate? If the page always uses x = new myclass
| >> to instantiate, the myclass constructor is always going to
| >> reinitialize its statebag.
| >>

|
|

Nov 19 '05 #5
Brad, send me an email and I can send you a sample implementation.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Right, so you'll create the helper and it will be empty until
LoadViewState is called. That's why it's important to forward the
overrides to the helper. So, yes, ViewState won't be loaded until the
Page base class calls the LoadViewState virtual.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Thanks for the reply....but you lost me there. If I'm using this in
a
page I understand about overriding the pages LoadViewState,
SaveViewState.. .and calling the helper class LoadViewState, etc...
The paradox I'm lost on is how the instance of the helper is saved
and
reinstantiated such that the value in it's statebag persist. The
page
needs to instantiate the helper somewhere. And if the helper has a
constructor which instantiates the statebag, the statebag (and thus
the viewstate) is going to be empty.
"Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
news:b8******** *************** ***@msnews.micr osoft.com...
This approach is typically done when a control (or the page) needs to
use
a helper object to track the viewstate. So the usage model is for the
control
to instantiate an instance of the helper object and then override all
of
the IStateManager APIs and call into the helper object for each one
(so
override
LoadViewState and the call into the helper's LoadViewState, etc...).
This
is how the helper object gets 'hooked into' the page model. I hope
that just
made sense :)
-Brock
DevelopMentor
http://staff.develop.com/ballen
I am creating a class (not a control) which implements
IStateManager. I've created the class and all of the implementations
(LoadView, SaveViewState, etc...). My Question is: How do I
instantiate this class in a page and then re-instantiate it on post
back such that I don't lose it's viewstate? If the page always uses
x = new myclass to instantiate, the myclass constructor is always
going to reinitialize its statebag.

Nov 19 '05 #6
Hi Brad,

How are you doing on this post. Does the suggestions in my last reply helps
a little? If there're anything else we can help, please feel free to post
here.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
--------------------
| X-Tomcat-ID: 54974071
| References: <Op************ **@TK2MSFTNGP09 .phx.gbl>
<b8************ **************@ msnews.microsof t.com>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online. microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Fri, 30 Sep 2005 03:38:33 GMT
| Subject: Re: IStateManager in a class object
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| Message-ID: <UL************ **@TK2MSFTNGXA0 1.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 111
| Path: TK2MSFTNGXA01.p hx.gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1281 62
| NNTP-Posting-Host: tomcatimport2.p hx.gbl 10.201.218.182
|
| Hi Brad,
|
| My understanding on your question is that you want your custom component
| class be able to automatically be able to utilize the asp.net page's
state
| management, (e.g. persist and load states into/from viewstate).
| If so, I'm afraid a normal class can not automatically hook into these
| process/ events model since the ASP.NET page doesn't know that it need to
| call your custom class's certain state mangement api. To achieve this, we
| need to override page class's LoadViewState/SaveViewState funciton or
hook
| into the Init ,Load, event so as to construct and populate your custom
| class's instance on the page. However I don't think this is possible for
a
| common component class.
|
| So the option left to us is just derive our class from the
| System.Web.UI.C ontrol, and when used on page, it is added into the
asp.net
| page's control collection. So that ASP.NET page will know that it need to
| call your object(control) 's state management methods at the proper time.
| Actually we can find some realworld examples like the DataSource controls
| in asp.net 2.0, though they're only utility components which haven't UI
| related task, they're still designed as Control since they need to hook
| into the asp.net page's runtime event model and state management steps.
|
| 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.)
|
|
|
|
| --------------------
| | Message-ID: <b8************ **************@ msnews.microsof t.com>
| | From: Brock Allen <ba****@NOSPAMd evelop.com>
| | Subject: Re: IStateManager in a class object
| | References: <Op************ **@TK2MSFTNGP09 .phx.gbl>
| | MIME-Version: 1.0
| | Content-Transfer-Encoding: 8bit
| | Content-Type: text/plain; charset=iso-8859-1; format=flowed
| | X-Newsreader: JetBrains Omea Reader 671.6
| | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | Date: Thu, 29 Sep 2005 14:55:26 -0700
| | NNTP-Posting-Host: host81-153-126-137.range81-153.btcentralpl us.com
| 81.153.126.137
| | Lines: 1
| | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| | Xref: TK2MSFTNGXA01.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:1281 15
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | Right, so you'll create the helper and it will be empty until
| LoadViewState
| | is called. That's why it's important to forward the overrides to the
| helper.
| | So, yes, ViewState won't be loaded until the Page base class calls the
| LoadViewState
| | virtual.
| |
| | -Brock
| | DevelopMentor
| | http://staff.develop.com/ballen
| |
| | > Thanks for the reply....but you lost me there. If I'm using this in a
| | > page I understand about overriding the pages LoadViewState,
| | > SaveViewState.. .and calling the helper class LoadViewState, etc...
| | > The paradox I'm lost on is how the instance of the helper is saved and
| | > reinstantiated such that the value in it's statebag persist. The page
| | > needs to instantiate the helper somewhere. And if the helper has a
| | > constructor which instantiates the statebag, the statebag (and thus
| | > the viewstate) is going to be empty.
| | >
| | > "Brock Allen" <ba****@NOSPAMd evelop.com> wrote in message
| | > news:b8******** *************** ***@msnews.micr osoft.com...
| | > This approach is typically done when a control (or the page) needs to
| | > use
| | > a helper object to track the viewstate. So the usage model is for the
| | > control
| | > to instantiate an instance of the helper object and then override all
| | > of
| | > the IStateManager APIs and call into the helper object for each one
| | > (so
| | > override
| | > LoadViewState and the call into the helper's LoadViewState, etc...).
| | > This
| | > is how the helper object gets 'hooked into' the page model. I hope
| | > that just
| | > made sense :)
| | > -Brock
| | > DevelopMentor
| | > http://staff.develop.com/ballen
| | >> I am creating a class (not a control) which implements IStateManager.
| | >> I've created the class and all of the implementations (LoadView,
| | >> SaveViewState, etc...). My Question is: How do I instantiate this
| | >> class in a page and then re-instantiate it on post back such that I
| | >> don't lose it's viewstate? If the page always uses x = new myclass
| | >> to instantiate, the myclass constructor is always going to
| | >> reinitialize its statebag.
| | >>
|
| |
| |
|
|

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2198
by: Kerry Neilson | last post by:
Hi, Really hung up on this one. I'm trying to get all the fields of a dictionary to be unique for each class: class A { my_dict = dict_entry = { 'key1':0, 'key2':0 } __init__(self): for x in range(10):
2
9600
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A, while an instance of class C should be able to check all methods #defined in C, B and A. #------------------------------------------------
6
3195
by: Brian Jones | last post by:
I'm sure the solution may be obvious, but this problem is driving me mad. The following is my code: class a(object): mastervar = def __init__(self): print 'called a'
18
6956
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I guess I'll try to narrow it down to a few specific questions, but any further input offered on the subject is greatly appreciated: 1. Are all of my class's methods supposed to take 'self' as their first arg? 2. Am I then supposed to call...
10
1661
by: lkrubner | last post by:
I killed last night and a good chunk of today trying to figure out this one particular attempt to get a class and initialize it. My code is using a class method called getObject to include() a file and then initialize the class in that file (one class per file, each file has the same name as the class). This code has been working fine for 8 months, and now is dying on this one line. Oddly, it is dying on the last return of this method. ...
3
1589
by: Chris Fink | last post by:
I have a question pertaining to the implementation of an interface's contract, specifically why in some interfaces the InterfaceName.method is required when other times just the Interfaces method name will work. For example, When using ICollection.CopyTo Method I can implement the CopyTo method as follows (notice the interface name is omitted): public void CopyTo(Array array, int index) {
5
3173
by: JH | last post by:
Hi I found that a type/class are both a subclass and a instance of base type "object". It conflicts to my understanding that: 1.) a type/class object is created from class statement 2.) a instance is created by "calling" a class object.
20
4042
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This tells me if a variable has changed, give me the original and current value, and whether the current value and original value is/was null or not. This one works fine but is recreating the same methods over and over for each variable type. ...
23
3148
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object model: that most OO features are not available for class object design without loss of POD-ness. So, I'm more than leaning toward "bad" because of the limitations and
0
10164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.