System.NullReferenceException: Object reference not set to an instance of an object.
-
user.aspx.cs: public partial class user : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = Session["val"].ToString(); } } login.aspx.cs: if (reader["pword"].ToString() == pswd.ToString()) { Session["val"] = TXtLoginName.Text; Response.Redirect("User.aspx"); } Still "Object reference not set to an instance of an object" error occurs :confused: sir. can u please help me?
-
user.aspx.cs: public partial class user : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = Session["val"].ToString(); } } login.aspx.cs: if (reader["pword"].ToString() == pswd.ToString()) { Session["val"] = TXtLoginName.Text; Response.Redirect("User.aspx"); } Still "Object reference not set to an instance of an object" error occurs :confused: sir. can u please help me?
Well, your code really sucks. You should not hard code session keys, you also should never check the session without first making sure the value is not null. You should step through in the debugger to try to work out if you are setting the session value, and why it's null on the other end. you should also not write code that returns the correct password, that's not secure.
Christian Graus Driven to the arms of OSX by Vista.