473,467 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Variables?!?

Hi All,

I don't understand why this is happing. If anyone knows this please fill me
in. I've simplified my question for the sake of simplicity that's why my
example sounds cheezy.

1. I have a VB.Net page with the following items:

-Textbox for Author
-Button for Okay
-A few other objects that cause postback events (eg DropDownList).

You enter an author's name into the textbox and press the okay button.

2. The page calls a C# object that takes the name and looks up the author in
a database. This information is returned as an object that is stored
locally on the page. It then lists the author's information from this
object in a table on the page. This part works fine.

3. Whenever any of the other items on the page cause a postback the returned
object becomes "Nothing" and the author's information is no longer
displayed.

How can I keep the object from being cleared during a postback event by the
other objects? The object is stored globally on the page so it should not
be destroyed. I store integer values on the page the same way and they
don't get cleared during a postback. What am I doing wrong?

Thanks,
Chris.
Nov 19 '05 #1
4 957
ChrisN wrote:
Hi All,

I don't understand why this is happing. If anyone knows this please fill me in. I've simplified my question for the sake of simplicity that's why my example sounds cheezy.

1. I have a VB.Net page with the following items:

-Textbox for Author
-Button for Okay
-A few other objects that cause postback events (eg DropDownList).

You enter an author's name into the textbox and press the okay button.
2. The page calls a C# object that takes the name and looks up the author in a database. This information is returned as an object that is stored locally on the page. It then lists the author's information from this object in a table on the page. This part works fine.

3. Whenever any of the other items on the page cause a postback the returned object becomes "Nothing" and the author's information is no longer
displayed.

How can I keep the object from being cleared during a postback event by the other objects? The object is stored globally on the page so it should not be destroyed. I store integer values on the page the same way and they don't get cleared during a postback. What am I doing wrong?


The Page should be assumed to be always destroyed after each request.
Your C# object can persist only if it's saved into viewstate (as your
integer values), Session, Cache, or AppState.

The default value of EnableViewState is true, so that all properties of
your Page are saved into the viewstate automatically. But your object
needs to be serializable, or have a TypeConverter defined, see
http://msdn.microsoft.com/library/de...eincontrol.asp

You may also use Cache instead of ViewState.

Nov 19 '05 #2
Thanks! I think I figured it out now.

"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
ChrisN wrote:
Hi All,

I don't understand why this is happing. If anyone knows this please

fill me
in. I've simplified my question for the sake of simplicity that's

why my
example sounds cheezy.

1. I have a VB.Net page with the following items:

-Textbox for Author
-Button for Okay
-A few other objects that cause postback events (eg DropDownList).

You enter an author's name into the textbox and press the okay

button.

2. The page calls a C# object that takes the name and looks up the

author in
a database. This information is returned as an object that is stored

locally on the page. It then lists the author's information from

this
object in a table on the page. This part works fine.

3. Whenever any of the other items on the page cause a postback the

returned
object becomes "Nothing" and the author's information is no longer
displayed.

How can I keep the object from being cleared during a postback event

by the
other objects? The object is stored globally on the page so it

should not
be destroyed. I store integer values on the page the same way and

they
don't get cleared during a postback. What am I doing wrong?


The Page should be assumed to be always destroyed after each request.
Your C# object can persist only if it's saved into viewstate (as your
integer values), Session, Cache, or AppState.

The default value of EnableViewState is true, so that all properties of
your Page are saved into the viewstate automatically. But your object
needs to be serializable, or have a TypeConverter defined, see
http://msdn.microsoft.com/library/de...eincontrol.asp

You may also use Cache instead of ViewState.

Nov 19 '05 #3
Does that mean if Page.EnableViewState is true (by default), then the Page
object is *not* destroyed for each request?

Thanks,
Simon

"Aquila Deus" <aq*********@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
ChrisN wrote:
Hi All,

I don't understand why this is happing. If anyone knows this please fill me
in. I've simplified my question for the sake of simplicity that's

why my
example sounds cheezy.

1. I have a VB.Net page with the following items:

-Textbox for Author
-Button for Okay
-A few other objects that cause postback events (eg DropDownList).

You enter an author's name into the textbox and press the okay

button.

2. The page calls a C# object that takes the name and looks up the

author in
a database. This information is returned as an object that is stored

locally on the page. It then lists the author's information from

this
object in a table on the page. This part works fine.

3. Whenever any of the other items on the page cause a postback the

returned
object becomes "Nothing" and the author's information is no longer
displayed.

How can I keep the object from being cleared during a postback event

by the
other objects? The object is stored globally on the page so it

should not
be destroyed. I store integer values on the page the same way and

they
don't get cleared during a postback. What am I doing wrong?


The Page should be assumed to be always destroyed after each request.
Your C# object can persist only if it's saved into viewstate (as your
integer values), Session, Cache, or AppState.

The default value of EnableViewState is true, so that all properties of
your Page are saved into the viewstate automatically. But your object
needs to be serializable, or have a TypeConverter defined, see

http://msdn.microsoft.com/library/de...eincontrol.asp
You may also use Cache instead of ViewState.

Nov 19 '05 #4
Simon Cheng wrote:
Does that mean if Page.EnableViewState is true (by default), then the Page object is *not* destroyed for each request?


It doesn't matter. The page is still destroyed, but all of its
properties are automatically saved into the viewstate.

Nov 19 '05 #5

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

Similar topics

2
by: Hal Vaughan | last post by:
First, I am aware of both SwingUtilities.invokeLater(), and of using Thread to create a new thread.  These are part of the problem. I want to have something running in the background, while the...
4
by: Torsten Bronger | last post by:
Hallöchen! I have a file that looks a little bit like a C header file with a long list of variables (actually constants) definitions, e.g. VI_ATTR_TIMO = 0x54378 .... Actually I need this...
1
by: mark4asp | last post by:
What are the best methods for using global constants and variables? I've noticed that many people put all global constants in a file and include that file on every page. This is the best way of...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
7
by: misha | last post by:
Hello. I was wandering if someone could explain to me (or point to some manual) the process of mapping the addresses of host variables by DB2. Especially I would like to know when DB2 decides to...
5
by: Sandman | last post by:
I dont think I understand them. I've read the section on scope in the manual inside out. I'm running PHP 5.2.0 Here is the code I'm working on: //include_me.php <?php $MYVAR = array(); global...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
4
by: icarus | last post by:
global_vars.py has the global variables set_var.py changes one of the values on the global variables (don't close it or terminate) get_var.py retrieves the recently value changed (triggered right...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
1
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.