Click here to Skip to main content
15,889,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to pass the object value from one page to another page using session in asp.net c#
Posted

From Login Page:
protected void loginbtn_Click(object sender, EventArgs e)
       {
           string username, password;
 
           username = unametxt.Text;
           password = pswdtxt.Text;
 
           Session["username"] = username;
           Session["password"] = password;
}


Another Page after Login:

C#
string username = Session ["username"].toString();
string pwd = Session ["password"].toString();
 
Share this answer
 
Comments
Member 8110943 18-Dec-12 1:10am    
string username = Session["uname"].ToString();
string password = Session["pwd"].ToString();
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_TRACK_USE";
cmd.Parameters.AddWithValue("@Username",username);
cmd.Parameters.AddWithValue("@Password", password);
cmd.Parameters.AddWithValue("@COMMAND", 1);
cmd.ExecuteScalar();
cn.Close();

sir,this code doesn,t store the logout time in database.so,please remove my pbm.
AshishChaudha 18-Dec-12 1:31am    
my vote
Member 8110943 18-Dec-12 1:44am    
hey,any1 give me answer...please
http://ramanisandeep.net/2008/11/21/passing-values-from-one-page-to-another-page-aspnet/[^]
http://shawpnendu.blogspot.in/2009/04/passing-dataparametersvalues-from-one.html[^]

C#
protected void loginbtn_Click(object sender, EventArgs e)
       {
           string username, password;

           username = unametxt.Text;
           password = pswdtxt.Text;

           Session["username"] = username;
           Session["password"] = password;
}
 
Share this answer
 
Comments
Member 8110943 18-Dec-12 1:00am    
how to code on logout button to pass the value from login page textbox to logout page and also want to store the logout into database..sir please reply i want full code of this pbm.
[no name] 18-Dec-12 1:09am    
Member 8110943 18-Dec-12 1:38am    
string username = Session["uname"].ToString();
string password = Session["pwd"].ToString();
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_TRACK_USE";
cmd.Parameters.AddWithValue("@Username",username);
cmd.Parameters.AddWithValue("@Password", password);
cmd.Parameters.AddWithValue("@COMMAND", 1);
cmd.ExecuteScalar();
cn.Close();
it work properly,but it doesn,t save the log outtime in databse,when i click on logout button..In default.aspx page username,password and a login button and in logout.aspx logout button are present.so please give me solution.
[no name] 18-Dec-12 7:40am    
for that take another session object like Session["LogOutTime"] and write code on LogOutBtn_Click, Session["LogOutTime"] = DateTime.Now;
There are many many to pass the value from one page to another.
You can pass value through Querystring or you can use Session for the same.

Thanks
 
Share this answer
 
Comments
Tarun Mangukiya 18-Dec-12 1:56am    
Ya. Right.

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