473,320 Members | 1,719 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,320 software developers and data experts.

Need basic help with classes

I have a User class that for example's sake looks something like this:

public class User
{
private int userId;
private string userName;
private string FirstName;
private string LastName;

public int UserId
{
get { return userId; }
set { userId = value; }
}
public int UserName
{
get { return userName; }
set { userName = value; }
}
public int FirstName
{
get { return firstName; }
set { firstName = value; }
}
public int LastName
{
get { return lastName; }
set { lastName = value; }
}
}

Now I understand if I want to create an instance of this on a code
behind page, I would do the following:

User user = new User();
user.UserId = 2;
etc....

What I want to know is, once I populate User with data, can I access
that data from a completely different page (than the one which
populated it or created the new instance)? Any help would be greatly
appreciated.

Aug 14 '06 #1
1 1007
Hi,

Ca*************@gmail.com wrote:
I have a User class that for example's sake looks something like this:

public class User
{
<snip>
}

Now I understand if I want to create an instance of this on a code
behind page, I would do the following:

User user = new User();
user.UserId = 2;
etc....

What I want to know is, once I populate User with data, can I access
that data from a completely different page (than the one which
populated it or created the new instance)? Any help would be greatly
appreciated.
The Page object is created on every request, and deleted every time that
the request is completed. It means that the objects belonging to the
Page must be recreated every time. That's the "stateless" approach.

However, you can save objects between roundtrips and share them between
pages by saving them in the Session. Each Page has a Session property,
which is created when the first request arrives, and which is deleted
only when the session is explicitly terminated, or when the session
timeout occurs (typically 20 minutes after the last request was processed).

To save an instance like you create in the session object, from within
the Page, you simply do

this.Session[ "aLabel" ] = user;

When you retrieve the object, you must cast it:

User user = (User) this.Session[ "aLabel" ];

If this is the first call, then the object will be null.

There are other strategies to persist objects between requests, but this
is probably the most standard one.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 14 '06 #2

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

Similar topics

1
by: Droolboy | last post by:
Hi, I'm about to start building a simple invoicing system for internal use, and am leaning towards using Java in some form. Thing is, there are so many ways it could be done, I'm having a hard...
41
by: Psykarrd | last post by:
I am trying to declare a string variable as an array of char's. the code looks like this. char name; then when i try to use the variable it dosn't work, however i am not sure you can use it...
2
by: tony collier | last post by:
i am learning c# and trying to use it to do a asp.net project at the same time. one of the biggest problems i have had was getting to understand all this OOP stuff since i last programmed in...
1
by: Juan Dent | last post by:
Hi, The Request.SaveAs method stores in a file the complete HTTP request including the HttpVersion. However when I try to reproduce in memory the same thing, I cannot find the "HTTP/1.1"...
17
by: Student | last post by:
Hi All, I have an assignment for my Programming language project to create a compiler that takes a C++ file as input and translate it into the C file. Here I have to take care of inheritance and...
21
by: Roland | last post by:
The following issue is puzzling me: There are 2 ways of writing the code below: .... Dim fnt as Font = New Font(...) DrawString(myText, fnt,...) fnt.dispose(). or DrawString(myText, New...
3
by: Simon Hart | last post by:
Hi, I am trying to implement some functionality as seen in MS CRM 3.0 whereby a basic Xml is deserialized into an object which contains properties. What I want to do from here is; cast the basic...
1
by: Tyno Gendo | last post by:
Hi everyone I need to move on a step in my PHP... I know what classes are, both in PHP4 and 5 and I'm aware of "patterns" existing, but what I'm looking for are some real world projects eg....
3
by: =?Utf-8?B?SmF5IFZpbnRvbg==?= | last post by:
I see general messages about how to learn .NET but I have an immediate requirement to ramp up my old skills very quickly. Can anyone recommend the FASTEST way for me to get almost-competent in...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.