一直提示未将对象引用设置到对象的实例,怎么回事啊???

2025-02-05 19:47:16
推荐回答(4个)
回答1:

问题可能出在你的第三行代码
if (this.currentPwd.Text == Session["password"].ToString())
当名为“password”为null时,Session["password"].ToString()会报这个错误。
建议修改为:
string pwd=string.Empty;
if(Session["password"]!=null)
{
pwd = Session["password"].ToString();
}

回答2:

Session["password"]没赋初始值?如果这个值是null,是不能.ToString()的

回答3:

if (this.newPwd.Text == this.confirmnewPwd.Text)

if (this.newPwd.Text !=null&& this.confirmnewPwd.Text!=null&&this.newPwd.Text == this.confirmnewPwd.Text)

回答4:

你确定你的控件名没写错?