how to create sessions?

Posted by Sriram under ASP.NET on 12/18/2012 | Points: 10 | Views : 1061 | Status : [Member] | Replies : 5
hi all,
how to create Sessions?

Thanks&Regards
sriram




Responses

Posted by: Hariinakoti on: 12/18/2012 [Member] Starter | Points: 25

Up
0
Down
session["UserName"]=txtusername.text;


Thanks & Regards
Hari

Sriram, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 12/18/2012 [Member] Starter | Points: 25

Up
0
Down
Check this url also

http://asp.net-tutorials.com/state/sessions/

Thanks & Regards
Hari

Sriram, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 12/18/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Save value in session
string n = "Your Value"; 

Session["a"] = n;

you also use textbox on place of n 'String'

on which page you want to retrive the session :---
Label1.Text = Session["a"].ToString(); 



Sriram, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 12/18/2012 [Member] Starter | Points: 25

Up
0
Down
write following code in ur login page submit button event to create user session
string username =TextBox1.Text;
Session["Loginname"] =username ;

and then to retrieve the value of session write the following code in ur master page.aspx.cs page...page load section and also attach one label to display user's name and one button to logout
if (Session["Loginname"] != null)

{

Label1 .Text = "Welcome : " + Session["Loginname"];
Button1.Text = "logout";
}
else
{
Label1.Text = "Welcome: Guest";
Button1.Text = "login";
}

}

protected void Button1_Click(object sender, EventArgs e)
{
if (Button1.Text =="logout")
{
Response.Redirect("logout.aspx");
Session["Loginname"] = null;
}
else if(Button1.Text =="login")
{
Response.Redirect("login.aspx");
}
}
}


please mark this answer if it helps u

Sriram, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 12/19/2012 [Member] Starter | Points: 25

Up
0
Down
sessions can be used to store the values... and the values can be accessed in any form of that project
To store the values in session. for eg in page1:
Session["Name"] = name;
//Here name is variable that is used in page1
//Name is a session variable that must not changed in the retrieving page.
To retriev the stored value in page2:
name = (string)Session["Name"];

Sriram, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response