473,378 Members | 1,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.Page-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["CurrentPosition"]? 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 1493
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"] = myIntegerPosition.

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.Page-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["CurrentPosition"]? 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********@gmail.comnapisal w wiadomosci
news:11**********************@b28g2000cwb.googlegr oups.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"] = myIntegerPosition.

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.Page-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["CurrentPosition"]? 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 #3

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

Similar topics

3
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...
6
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...
6
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...
31
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...
2
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...
1
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....
15
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...
3
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...
13
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...
2
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.