Click here to Skip to main content
15,912,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when a person has loged in he's directed to a page in which all his details are present defaultly i.e during the page load itself.i need the code that has to be written under the page load using sessions please help me out.
Posted
Comments
Yusuf 24-Aug-10 5:29am    
If we give you the code, then what is your contribution towards what you are building?
srujanac# 24-Aug-10 5:59am    
unable to complete this
if (ds.Tables[0].Rows[0].Columns.Count > 0) { txtemployeeid1=co.... }

1 solution

First make a serializable class with data members which actually represents the data of the logged in person. Instantiate the class, put the data values and Serialize it in Session. In the target page deserialize the object and bind the data members values to specific controls.

Something like the following piece of code:

1. Create a serializable class

[Serializable]
public class UserData
{
   private string _userFirstName;
   prvate string _userLastName;
   ....................
   ....................
   public string FirstName
   {
    get{return this._userFirstName;}
    set{this._userFirstName = value;}
   }
   .................................
   ...................
}


2. Serialize the class in the Login.aspx.cs class

if(Authenticated)
{
  UserData objUserData = new UserData();
  objUserData.FirstName = "John";
  objUserData.LastName = "Scott";
  ..............................
  ................................
 Session.Add("UserData",objUserData);
}


3. Deserialize the object from Session and bind the values to the property in the targeted pages Load method.

protected void Page_Load(object sender, EventArgs e)
{
   UserData objUserData = (UserData)Session["UserData"];
   lblUserFirstName.Text = objUserData.FirstName;
   lblUserLastName.Text = objUserData.LastName;
   .............................................
   ........................................
}


Hope this helps you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900