here is some example hope it helps you to understand session
protected void btnImage_Click(object sender, ImageClickEventArgs e)
{
try
{
adp = new SqlDataAdapter("Select UserName from AdminLogin where UserName='" + txtusername.Text + "' and Password='" + txtpassword.Text + "'", conn);
tbl = new DataTable();
adp.Fill(tbl);
if (tbl.Rows.Count == 0)
{
cls.MsgBox("Invalid UserName or Password...Login Failed", this.Page);
txtpassword.Focus();
return;
}
Session["User"] = tbl.Rows[0]["UserName"].ToString();
Session["SessionId"] = "valid";
Server.Transfer("Default.aspx");
}
catch (Exception ex)
{
cls.MsgBox(ex.Message, this.Page);
}
}