By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

"Page" class and utility class

P: n/a
Hello All,

I have written a webform which is by default derived from "Page" class. I
have coded another utility class with few methods and an object of this class
is instantiated from the webfom class.

Methods inside the utility class set few global variables which act as
mediums of persistence to hold data. Now my question is all works fine during
my initial request and all the global variables are set correctly, but during
later requests I doubt that global variables are holding null references. Can
anyone give me a suitable explanation on this?

I know that Page class is completely destroyed in the "Unload" method of the
lifecycle but how about the utility class? Would it even be destroyed along
with the webform class?

Thanks for your pointers!!
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You can persist through app variables, to some extent. Beyond that use a
DB/File/etc to persist data.

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
Hello All,

I have written a webform which is by default derived from "Page" class. I
have coded another utility class with few methods and an object of this
class
is instantiated from the webfom class.

Methods inside the utility class set few global variables which act as
mediums of persistence to hold data. Now my question is all works fine
during
my initial request and all the global variables are set correctly, but
during
later requests I doubt that global variables are holding null references.
Can
anyone give me a suitable explanation on this?

I know that Page class is completely destroyed in the "Unload" method of
the
lifecycle but how about the utility class? Would it even be destroyed
along
with the webform class?

Thanks for your pointers!!

Nov 19 '05 #2

P: n/a
Does your reply mean that the utility class's object is also destroyed in the
Page's Unload method?
"Curt_C [MVP]" wrote:
You can persist through app variables, to some extent. Beyond that use a
DB/File/etc to persist data.

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
Hello All,

I have written a webform which is by default derived from "Page" class. I
have coded another utility class with few methods and an object of this
class
is instantiated from the webfom class.

Methods inside the utility class set few global variables which act as
mediums of persistence to hold data. Now my question is all works fine
during
my initial request and all the global variables are set correctly, but
during
later requests I doubt that global variables are holding null references.
Can
anyone give me a suitable explanation on this?

I know that Page class is completely destroyed in the "Unload" method of
the
lifecycle but how about the utility class? Would it even be destroyed
along
with the webform class?

Thanks for your pointers!!


Nov 19 '05 #3

P: n/a
I believe it will be yes.

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.com...
Does your reply mean that the utility class's object is also destroyed in
the
Page's Unload method?
"Curt_C [MVP]" wrote:
You can persist through app variables, to some extent. Beyond that use a
DB/File/etc to persist data.

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
> Hello All,
>
> I have written a webform which is by default derived from "Page" class.
> I
> have coded another utility class with few methods and an object of this
> class
> is instantiated from the webfom class.
>
> Methods inside the utility class set few global variables which act as
> mediums of persistence to hold data. Now my question is all works fine
> during
> my initial request and all the global variables are set correctly, but
> during
> later requests I doubt that global variables are holding null
> references.
> Can
> anyone give me a suitable explanation on this?
>
> I know that Page class is completely destroyed in the "Unload" method
> of
> the
> lifecycle but how about the utility class? Would it even be destroyed
> along
> with the webform class?
>
> Thanks for your pointers!!


Nov 19 '05 #4

P: n/a
it depend on how the utility class is coded and used. if you webform creates
an instance of the utility class, it will be released at the end of the page
process. all pages will see there own instance data. if the utiltity class
has any shared or static variables, these live the life of the appdomain,
and any page request sees the same values. if you do not use some locking
techinque you will have threading issues.

-- bruce (sqlwork.com)

"Diffident" <Di*******@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
| Hello All,
|
| I have written a webform which is by default derived from "Page" class. I
| have coded another utility class with few methods and an object of this
class
| is instantiated from the webfom class.
|
| Methods inside the utility class set few global variables which act as
| mediums of persistence to hold data. Now my question is all works fine
during
| my initial request and all the global variables are set correctly, but
during
| later requests I doubt that global variables are holding null references.
Can
| anyone give me a suitable explanation on this?
|
| I know that Page class is completely destroyed in the "Unload" method of
the
| lifecycle but how about the utility class? Would it even be destroyed
along
| with the webform class?
|
| Thanks for your pointers!!
Nov 19 '05 #5

P: n/a
Diffident wrote:
I have written a webform which is by default derived from "Page" class. I
have coded another utility class with few methods and an object of this class
is instantiated from the webfom class.

Methods inside the utility class set few global variables which act as
mediums of persistence to hold data. (abridged)

I know that Page class is completely destroyed in the "Unload" method of the
lifecycle but how about the utility class? Would it even be destroyed along
with the webform class?

You haven't got "global variables" in object oriented programming
environments, so I except that you refer to either:
1. Field on the utility class
2. Application or Session variables.

If the utility class is instantiated from the webform class and no other
"living" class holds a reference to the class the utility class is
marked for garbage collection. A new instance of the utility class will
be created when a new request for the page is handled.
If you store values data in the fields of the utility class (scenario 1)
the data dies with the class.
If you store the data in either session or application variables
(scenario 2), the data can be retrieved on subsequent requests.

A third posibility is to store the data in the page's view state.
To store a value in and retrieve it from the view state do this (C#):
if (Page.IsPostBack) {
// Read from view state
RegTot=(string) ViewState["MyValue"];
} else {
// Store in view state
ViewState["MyValue"] = RegTot;
}

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.