I am using session to carry the value to another page in ASP.NET using C#, but the page I am redirecting to is getting null value. However, I tried passing value through session in simple application, and it's working well. Please help me out where am I going wrong?
// Login.aspx.cs
con.Open();
cmd = new SqlCommand("select Username, Password, Fname from Customer where Username = '" + txtCust.Text + "' and Password = '" + txtPass3.Text + "'",con);
rd = cmd.ExecuteReader();
if (rd.Read())
{
a = rd.GetValue(0).ToString();
b = rd.GetValue(1).ToString();
c = rd.GetValue(2).ToString();
}
con.Close();
if (a != txtCust.Text)
Response.Write("<script>alert('Invalid Username')</script>");
else if (b != txtPass3.Text)
Response.Write("<script>alert('Invalid Password')</script>");
else
{
Session["user"] = c;
Response.Redirect("Customer_Home.aspx");
}
// Customer_Home.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] != null)
{
lblUser.Text = Session["user"].ToString();
}
else
{
lblUser.Text = "No value returned";
}
}
I expect the output of the above code to be "Fname", but the actual output is "No value returned"