Problem in Making Change Password Page In ASP.Net

It shows the folloing error:-"Object reference not set to an instance of an object.

Coding is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Configuration;
using System.Data.SqlClient;

namespace housing1.Admin
{
    public partial class Change_Password : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HiddenFieldUN.Value=Request.QueryString["uname"];
        }


        protected void OnChangingPassword(object sender, LoginCancelEventArgs e)
        {
            if (!ChangePassword1.CurrentPassword.Equals(ChangePassword1.NewPassword, StringComparison.CurrentCultureIgnoreCase))
            {
                int rowsAffected = 0;
                string query = "UPDATE [UserData] SET [Password] = @NewPassword WHERE [USerName] = @Username AND [Password] = @CurrentPassword";
                string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = new SqlCommand(query))
                    {
                        using (SqlDataAdapter sda = new SqlDataAdapter())
                        {
                            cmd.Parameters.AddWithValue("@Username", HiddenFieldUN.Value);
                            cmd.Parameters.AddWithValue("@CurrentPassword", ChangePassword1.CurrentPassword);
                            cmd.Parameters.AddWithValue("@NewPassword", ChangePassword1.NewPassword);
                            cmd.Connection = con;
                            con.Open();
                            rowsAffected = cmd.ExecuteNonQuery();
                            con.Close();
                        }
                    }
                    if (rowsAffected > 0)
                    {
                        lblMessage.ForeColor = Color.Green;
                        lblMessage.Text = "Password has been changed successfully.";
                    }
                    else
                    {
                        lblMessage.ForeColor = Color.Red;
                        lblMessage.Text = "Password does not match with our database records.";
                    }
                }
            }
            else
            {
                lblMessage.ForeColor = Color.Red;
                lblMessage.Text = "Old Password and New Password must not be equal.";
            }

            e.Cancel = true;
        }

    }
}

Open in new window

"

The Flow of Project is as follows:
1) Login Page
2)Admin_Panel
3)Change_Password
Login.aspx
Login.aspx.cs
Admin_Panel.aspx
Admin_Panel.aspx.cs
Change_Password.aspx
Change_Password.aspx.cs
Sukesh ShuklaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Easwaran ParamasivamCommented:
Did you debug the application? At which line of code it throws exception?
0
Sukesh ShuklaAuthor Commented:
It Shows error in

 string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
0
Easwaran ParamasivamCommented:
In your config file, <ConnectionStrings> section has the key "constr"? It is case sensitive. Kindly check.

Reference: http://www.codeproject.com/Tips/416198/How-to-get-Connection-String-from-App-Config-in-Cs
0
Naitik GamitSoftware DeveloperCommented:
You appear to be trying to retrieve a connection string by using the string itself as the name...which is why you get the error, it doesn't exist so it returns null.

Take different names of your connection string and your string variable:
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

You can take as like :
string strconn = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.