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

Problem accessing Properties of class, not sure if class

Hi, I've got a User class which holds details of the user and is populated by
a query. I create this User object when the user successfully logs in and
then I set this object to a session variable (its for a ASP.Net site) so that
I can access any of the user's details from this session object.
The problem is when I'm trying to access a Property of the object, the
intellisence does not display the Property name. So when I type in:

Session["user"]. I only get the standard object methods.

This is how my class looks:

public class User
{
private string username;
private string firstname;
private string lastname;
private string password;
private string email;
private string roleID;
protected string userType;

public User(string _username, string _password)
{
Username = _username;
Password = _password;
GetUserDetails(Username, Password);
}

#region "Properties"
public string Username
{
get { return username; }
set { username = value.Trim();}
}

public string Password
{
get { return password; }
set { password = value.Trim(); }
}

public string Firstname
{
get { return firstname; }
set { firstname = value.Trim();}
}

public string Lastname
{
get { return lastname; }
set { lastname = value.Trim(); }
}

public string Email
{
get { return email; }
set { email = value; }
}

public string RoleID
{
get { return roleID; }
set { roleID = value; }
}

public string UserType
{
get { return userType; }
set
{
if (value == "1")
{
userType = "Expert";
}
if (value == "2")
{
userType = "Basic";
}
}
}
#endregion

protected void GetUserDetails(string _username, string _password)
{
DataSet ds = UserDAO.GetUserDetails(_username, _password);

foreach (DataRow dr in ds.Tables["User"].Rows)
{
Firstname = dr["firstname"].ToString();
Lastname = dr["lastname"].ToString();
RoleID = dr["RoleID"].ToString();
UserType = dr["RoleID"].ToString().TrimEnd();

}

}
}
What gives??

Jul 27 '06 #1
3 1157
session[whatever] doesn't know (at compile time) what your object is;
you just need to cast to the User:

User user = (User) session["user"];

or whatever; this line could be exposed (via a property) in a
base-class for the pages, so that actually pages just call .CurrentUser
(or whatever) and it is made available easily.

Marc

Jul 27 '06 #2
Thanks Marc,

"Marc Gravell" wrote:
session[whatever] doesn't know (at compile time) what your object is;
you just need to cast to the User:

User user = (User) session["user"];

or whatever; this line could be exposed (via a property) in a
base-class for the pages, so that actually pages just call .CurrentUser
(or whatever) and it is made available easily.

Marc

Jul 27 '06 #3
Hi,
You can also use ((User)Session["user"]).Property

BTW, it's wise to check for null first, if the session expired you may not
have an instance in the session and you will get an exception.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"MicroMoth" <st***********@forvus.co.ukwrote in message
news:15**********************************@microsof t.com...
Thanks Marc,

"Marc Gravell" wrote:
>session[whatever] doesn't know (at compile time) what your object is;
you just need to cast to the User:

User user = (User) session["user"];

or whatever; this line could be exposed (via a property) in a
base-class for the pages, so that actually pages just call .CurrentUser
(or whatever) and it is made available easily.

Marc


Jul 27 '06 #4

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

Similar topics

17
by: Dave | last post by:
Hi I'm making a 3D Engine which consists of the class C3DEngine. Part of this engine is a file loader, a class called CMeshLoader. I have made an instance of CMeshLoader in C3DEngine, ie...
1
by: Steven Blair | last post by:
Hi, Here is a short decsription of my problem. I have written a dll for Database accessing. I have one method which can return a Dataset and another method which takes a Dataset and upates a...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
8
by: dwok | last post by:
I have been wondering this for a while now. Suppose I have a class that contains some private member variables. How should I access the variables throughout the class? Should I use properties that...
5
by: Cyril Gupta | last post by:
Hello, I have a class inside another class. The Scenario is like Car->Engine, where Car is a class with a set of properties and methods and Engine is another class inside it with its own set of...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
6
by: evandelagrammaticas | last post by:
Hi all. I have spent the better part of a day scouring the newsgroups and I am sure that I must have come across the solution a number of times - but I am still a real newbie at asp.net so please...
4
by: Suresh | last post by:
Is there any way to access the custom properties of a master page from the aspx form? I know the custom properties of a master page can be accessed from the aspx.cs partial class by specifying...
8
by: RSH | last post by:
Hi, I have a situation where I have a Parent Object (Company) which has several public properties. The Company Object also creates an Employees object which has its ow set of functions and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
0
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,...

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.