-2
    protected void Page_Load(object sender, EventArgs e)
    {
        lb_msg2.Text = "Hello " + Session["userid"].ToString() + "!";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["ProfileCS"].ConnectionString;

        string sql = "Select password from Profile where userid = '" + Session["userid"] + "'";
        SqlCommand cmd = new SqlCommand();
        SqlDataReader dr; // to hold reference of datareader  returned

        //prepare  a place - datatable to hold the data
        DataTable dt = new DataTable();

        //setting up command
        cmd.CommandText = sql;
        cmd.Connection = con;

        //connection and execute command
        con.Open();
        dr = cmd.ExecuteReader();

        dt.Load(dr); // copy data from datareader to datatable

        string pwdcheck;
        pwdcheck = dt.Rows[0]["password"].ToString();

        if (tb_verify.Text.Equals(pwdcheck))
        {
            string password = tb_pwd.Text;

            sql = "Update Profile set password ='" + password + "'";
            sql = sql + "where userid = '" + Session["userid"] + "'";

            cmd.CommandText = sql;
            cmd.Connection = con;

            try
            {
                cmd.ExecuteNonQuery();
                lb_msg.Text = "Password changed succesfully";
            }
            catch (Exception ex)
            {
                lb_msg.Text = "Problems encountered " + ex.Message;
            }


            finally
            {
                con.Close();
                con.Dispose();
                cmd.Dispose();
            }
        }
        else
            lb_msg.Text = "Old password Incorrect";
    }

    protected void lblClick(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Session.Clear();  // This may not be needed -- but can't hurt
        Session.Abandon();
        FormsAuthentication.RedirectToLoginPage();
    }
}

lb_msg2.Text = "Hello " + Session["userid"].ToString() + "!";

there is an error at the line above with Object reference not set to an instance of an object the change password feature was working before.

Saghir A. Khatri
  • 3,341
  • 6
  • 40
  • 73
sherrez
  • 33
  • 2
  • 7

1 Answers1

1

In your case Session["userid"] must be NULL,handle it

Cris
  • 10,774
  • 5
  • 30
  • 47
  • yo what does that mean leave it as null in my database – sherrez Jan 07 '14 at 07:18
  • your session must have expired so value of Session["userid"] is null,thats why you are getting error at Session["userid"].ToString() – Cris Jan 07 '14 at 07:20