未将对象引用设置到对象的实例。修改密码就出现这个问题

using System;
using System.Data;
using System.Configuration;
using System.Collections;
public partial class XueShengMod : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox2.Text == "" || this.TextBox3.Text == "")
{
Response.Write("alert('密码不能为空!');document.location=document.location;");
}
if
(this.TextBox1.Text!=Session["PWD"].ToString())
{
Response.Write("alert('旧密码不对!');document.location=document.location;");
}
else if (this.TextBox2.Text == this.TextBox3.Text)
{
string sql = "update TB_XueSheng set PassWord='" + this.TextBox2.Text + "' where XueHao='" + Session["username"].ToString() + "'";
bool b = DBHelper.ExecSql(sql);
if (b)
{

未将对象引用设置到对象的实例。
源错误:
行 22: Response.Write("alert('密码不能为空!');document.location=document.location;");
行 23: }
行 24: if
行 25: (this.TextBox1.Text!=Session["PWD"].ToString())
行 26: {

使用session前最好判断下session是否为空,要不超时后session为空调用ToString就报错了

 protected void Button1_Click(object sender, EventArgs e)
{
if(Session["username"]==null||Session["pwd"]==null){/////////
  Response.Write("超时!");
    Response.End();///////
}
if (this.TextBox2.Text == "" || this.TextBox3.Text == "")

Session["PWD"]
是否存在这个值

应该就是session中的值没有,没有的话,你要在使用前先放到session中,具体在哪放,你自己定

if (Session["PWD"] != null)
你的代码

应该就是session中的值没有,没有的话,你要在使用前先放到session中,具体在哪放,你自己定