473,808 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2.0: Session variables vs class-page fields

RAM
Hello,
I am learning ASP.NET 2.0. Could you explain me please the difference when
to use fields of a System.Web.UI.P age-derived class and whem I must use
Session variable instead. For example I have a class PZ : System.Web.UI.P age
and I need to remember CurrentPosition (int) of asp:DataList. Can I use
private field of PZ class (even in multiuser ASP.NET application) or I have
to use Session["CurrentPositio n"]? For unknown reason I have null in
PositionsTable (DataTable, field) after next page unload/load although I
assign non-null object to PositionsTable in some event-handler function.
Please help. Thank you!
/RAM/

Oct 9 '06 #1
2 1516
An instance of your page class is created and destroyed for each
request. The values of class field members are not persisted across
requests and must be placed in a longer-lived mechanism if you want to
keep them.

For something like the selected element in a DataList, your best bet is
ViewState["myKey"] = myIntegerPositi on.

That's how the Asp.Net controls store info across postbacks and, used
sensibly, it's a decent way of storing info. Don't stick anything huge
in there though, because it will be sent/received for each request as
part of the generated HTML.

RAM wrote:
Hello,
I am learning ASP.NET 2.0. Could you explain me please the difference when
to use fields of a System.Web.UI.P age-derived class and whem I must use
Session variable instead. For example I have a class PZ : System.Web.UI.P age
and I need to remember CurrentPosition (int) of asp:DataList. Can I use
private field of PZ class (even in multiuser ASP.NET application) or I have
to use Session["CurrentPositio n"]? For unknown reason I have null in
PositionsTable (DataTable, field) after next page unload/load although I
assign non-null object to PositionsTable in some event-handler function.
Please help. Thank you!
/RAM/
Oct 9 '06 #2
RAM
Thanks a lot!

Uzytkownik "Flinky Wisty Pomm" <Pa********@gma il.comnapisal w wiadomosci
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
An instance of your page class is created and destroyed for each
request. The values of class field members are not persisted across
requests and must be placed in a longer-lived mechanism if you want to
keep them.

For something like the selected element in a DataList, your best bet is
ViewState["myKey"] = myIntegerPositi on.

That's how the Asp.Net controls store info across postbacks and, used
sensibly, it's a decent way of storing info. Don't stick anything huge
in there though, because it will be sent/received for each request as
part of the generated HTML.

RAM wrote:
>Hello,
I am learning ASP.NET 2.0. Could you explain me please the difference
when
to use fields of a System.Web.UI.P age-derived class and whem I must use
Session variable instead. For example I have a class PZ :
System.Web.UI. Page
and I need to remember CurrentPosition (int) of asp:DataList. Can I use
private field of PZ class (even in multiuser ASP.NET application) or I
have
to use Session["CurrentPositio n"]? For unknown reason I have null in
PositionsTab le (DataTable, field) after next page unload/load although I
assign non-null object to PositionsTable in some event-handler function.
Please help. Thank you!
/RAM/

Oct 9 '06 #3

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

Similar topics

3
6047
by: Nhi Lam | last post by:
Hi, I understand that there are 3 modes in which I can configure the SessionStateModule. What I need is an out of process Session State store with fail over support. The "SQL Server Mode" seems to be it, but I heard there is quite a bit of degradation in performance for using this mode. My next option is the "State Server Mode". However, this mode does not give me the fail over support. Is there anything that I can do the enhance the...
6
1788
by: Hans Kesting | last post by:
Hi, When the Session_OnEnd event fires, do the Session variables still exist? I want to do some cleanup (update some records in a database etc.), but then I need to know *which* recopds to update ... Can I access these session variables through HttpContext.Current.Session ? (the cleanup-code is in a separate class, which is defined within the website)
6
1273
by: Just D | last post by:
Hi, How slowly is to work with these objects - Application and Session ? Is it much better to create a huge project or some static library and place all variables/constants there instead of many Session objects? When I removed some of Session objects and replaced by another approaches I got an illusion that application started working significantly faster? Is it true?
31
7013
by: Harry Simpson | last post by:
I've come from the old ASP camp where session variables were not used. When i started using ASP.NET in 2001, I started using them again because it was ok from what I'd read. I've been merrily using Session variables for three years now and i'm entering a project with my new boss who has never quite come around that session variables are ok. What's the concensus here. How can i convince him that they are ok in ASP.NET. OR
2
2292
by: Stuart | last post by:
Hi there I am using several processes within an .asp application that store variables in to session - typically: Session("UniqueName") = Value I am having a hell of a time overwriting the Session value once it has been stored the first time - namely I can't
1
3788
by: aliendolphin | last post by:
I'm having a strange problem possibly with Session variables for one user being accessed by another. I use a static utility class with static methods which get and set certain Session variables. For Example: public static string UserEmail { get { return HttpContext.Current.Session; } set { HttpContext.Current.Session = value; }
15
2536
by: Jason | last post by:
Currently, I am storing information about the currently logged on user in Session variables that are stored in SQL. However, I am using role-based security, so I am storing custom roles in a GenericPrincipal object that I attached to Context.User. My question is this: Can I create a new class, ExtendedPrincipal for instance, and simply inherit System.Security.Principal and store all of the information currently stored in Session...
3
2915
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have any experience on how to keep track of session value. Any help it's appreciated. Thanks Alan
13
1767
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object? Thanks, Jerry
2
7032
by: Ibrahim. | last post by:
Hello, My question is simple. If Session variables were to be assigned a value inside a shared function, does the session data visible to other sessions (Other users). I know the variables used inside the shared function are shared as well, is it same for session variables...? example vb.net;
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10628
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...
0
10113
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
9195
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
7651
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
6880
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
5547
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
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
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

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.