473,805 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q - How do I persist members variables/properties on Page level?

I know I can use ViewState for member fields and variables declared on
Page level to persist between postbacks, for example:

private const string FormModeTag = "_FormMode_ ";

private string FormMode
{
get
{
object formMode = this.ViewState[FormModeTag];
if( formMode != null )
{
return (string)formMod e;
}
else
{
return "";
}
}
set
{
this.ViewState[FormModeTag] = value;
}
}
Is there some other and/or better way? I found PersistentMode
attribute, but it seems it only works with controls' properties, not
with Page properties.

Thanks!

Nov 19 '05 #1
5 2369
ViewState is considered the best practice (in almost all cases) for
persisting a value between postbacks on the same page. It has the perfect
scope for such an operation. There are of course other caching options but
they have a less than ideal scope.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Usenet User" < @ . > wrote in message
news:3i******** *************** *********@4ax.c om...
I know I can use ViewState for member fields and variables declared on
Page level to persist between postbacks, for example:

private const string FormModeTag = "_FormMode_ ";

private string FormMode
{
get
{
object formMode = this.ViewState[FormModeTag];
if( formMode != null )
{
return (string)formMod e;
}
else
{
return "";
}
}
set
{
this.ViewState[FormModeTag] = value;
}
}
Is there some other and/or better way? I found PersistentMode
attribute, but it seems it only works with controls' properties, not
with Page properties.

Thanks!

Nov 19 '05 #2
> Is there some other and/or better way?

What do you mean? This is the model for insuring a value is passed back and
forth between postbacks.
I found PersistentMode
attribute, but it seems it only works with controls' properties, not
with Page properties.


PersistMode has to do with how the syntax in the ASPX is interpreted by the
ASP.NET parser. It has nothing to do with ViewState.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #3
> Is there some other and/or better way?

ViewState is a tool. Asking if there's a better way is like asking if there
is a better tool than a hammer. It all depends on what you are doing. A
hammer is perfect for hammering nails, but lousy at cutting plywood.

The most important thing is to know what all of your tools are, what each
one is used for, what its characteristics are, and when it is appropriate to
use it.

ViewState, for example, is not particularly good for storing large chunks of
data. It slows down the Response time by adding to the content of the Page.
It is, however, perfect for storing the state of a Server Control, which is
very small. It has the advantage of not consuming resources (memory) on the
server side.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Usenet User" < @ . > wrote in message
news:3i******** *************** *********@4ax.c om...
I know I can use ViewState for member fields and variables declared on
Page level to persist between postbacks, for example:

private const string FormModeTag = "_FormMode_ ";

private string FormMode
{
get
{
object formMode = this.ViewState[FormModeTag];
if( formMode != null )
{
return (string)formMod e;
}
else
{
return "";
}
}
set
{
this.ViewState[FormModeTag] = value;
}
}
Is there some other and/or better way? I found PersistentMode
attribute, but it seems it only works with controls' properties, not
with Page properties.

Thanks!

Nov 19 '05 #4
On Thu, 24 Mar 2005 09:12:57 -0500, "Kevin Spencer"
<ke***@DIESPAMM ERSDIEtakempis. com> wrote:
Is there some other and/or better way?


ViewState is a tool. Asking if there's a better way is like asking if there
is a better tool than a hammer. It all depends on what you are doing. A
hammer is perfect for hammering nails, but lousy at cutting plywood.

The most important thing is to know what all of your tools are, what each
one is used for, what its characteristics are, and when it is appropriate to
use it.

ViewState, for example, is not particularly good for storing large chunks of
data. It slows down the Response time by adding to the content of the Page.
It is, however, perfect for storing the state of a Server Control, which is
very small. It has the advantage of not consuming resources (memory) on the
server side.


Thank you all who responded, I am getting the idea. I only see a
couple of drawbacks with ViewState:

1) Must be implemented manually, per each variable/property.

2) Uncovers the inner data of the class by sending it to the client.
What if it is not meant to be seen?

Nov 19 '05 #5
ViewState is encoded so its content cannot be easily seen by a typical user.
Also, ViewState can be configured to be stored on the server instead of the
client, if you prefer.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Usenet User" < @ . > wrote in message
news:d5******** *************** *********@4ax.c om...
On Thu, 24 Mar 2005 09:12:57 -0500, "Kevin Spencer"
<ke***@DIESPAMM ERSDIEtakempis. com> wrote:
Is there some other and/or better way?


ViewState is a tool. Asking if there's a better way is like asking if
there
is a better tool than a hammer. It all depends on what you are doing. A
hammer is perfect for hammering nails, but lousy at cutting plywood.

The most important thing is to know what all of your tools are, what each
one is used for, what its characteristics are, and when it is appropriate
to
use it.

ViewState, for example, is not particularly good for storing large chunks
of
data. It slows down the Response time by adding to the content of the
Page.
It is, however, perfect for storing the state of a Server Control, which
is
very small. It has the advantage of not consuming resources (memory) on
the
server side.


Thank you all who responded, I am getting the idea. I only see a
couple of drawbacks with ViewState:

1) Must be implemented manually, per each variable/property.

2) Uncovers the inner data of the class by sending it to the client.
What if it is not meant to be seen?

Nov 19 '05 #6

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

Similar topics

9
3651
by: Pack Fan | last post by:
I've noticed that session variables will persist on Mac IE even after all browser windows have been closed. One must quit the program to clear the session variables. This presents a security risk for my session variable based security scheme. Basically, the risk is that a user will login to my site, close the window when done and allow someone else to come up to the machine, go back to my site and be logged into the previous user's...
14
3258
by: Paul Yanzick | last post by:
Hello, I am trying to develop a book tracking application for my capstone in school, and am running into a problem. The application is an ASP.Net application written in C#. The first page you go to is a login form, which will set several session variables with the name used to log in, appropriate security level and some other misc variables, and then will go to a main menu for each particular security level using Server.Transfer. ...
3
10890
by: Joe Fromm | last post by:
Perhaps I'm missing something obvious, but I've been curious about one of the coding practices I see advocated. I'm a longtime C/C++ programmer trying to learn C#, and I started looking around for coding standards/best practices. Several of the documents I've read require that all members be private (or protected), and the get/set properties be provided for any elements exposed to the outside world. In C++ this makes perfect sense,...
1
2466
by: John Cosmas | last post by:
I'm reusing my top and bottom borders by using placeholders. I need to pass public level variables from the parent to the child instead of using Session variables. How could I do that so that the child level ASCX files can read what the parent uses?
11
3850
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of ways to do this through prototyping and other techniques, but these behaviors need to be static and...
2
2015
by: Tomas Martinez | last post by:
Hi, Well, my problem is so simple as it says in the subjet but very frustrating also. I have a project and it is losing the session variables with each postback, so I downloaded from the web a project which used a session management dll to discover what was wrong in my project. This web project has two pages, one send to the other a variable with session state and the other changes this one, shown in a label, with each postback, well,...
0
3269
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design time. If I type the code in the aspx manually it does get parsed correctly though. This is an example of the aspx code that gets parsed correctly. For some reason, if I changed update the Tab property of the control through the GUI at design...
2
3994
by: Rob Long | last post by:
Hi there Is there any way to access private variables directly from within a priviliged function? I have a situation where the priviliged function's execution context contains variables of the same name as the parent context, but I want direct access to the parent context's variable. E.g. I would like to be able to do this... function Point()
7
1311
by: Andy B | last post by:
I have an instance of an object that needs to be accessed by all members of a page like page_load, button_click events and so on. Where in the codebehind would I put the creation of the object instance?
0
10614
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
10369
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
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
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
7649
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
6876
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
5544
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...
1
4327
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
3008
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.