Arrhythmias 2015-05-21 12:08 采纳率: 25%
浏览 1541
已采纳

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

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: {

  • 写回答

5条回答 默认 最新

  • Go 旅城通票 2015-05-21 13:29
    关注

    使用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 == "")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?