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条)

报告相同问题?

悬赏问题

  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊