谁能解决这个问题? [英] can any one solve this?

查看:64
本文介绍了谁能解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他正在尝试更改密码,但出现错误
对象引用未设置为对象的实例..

页面加载

hi am trying to change password but am getting error
object referance is not set to an instance of an object..

page load

protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           Label3.Text = Session["LoginName"].ToString();
           Label2.Visible = false;
           Label3.Visible = true;
       }
   }




这是我的更新代码..




here is my update code..

protected void btnSave_Click(object sender, ImageClickEventArgs e)
   {
       Label3.Text = Session["USERNAME"].ToString();//this line am getting error
       objPL.lnLoginName = Session["USERNAME"].ToString();
       objPL.newPassword = TextBox3.Text;
       objBLL.ChangePassword(objPL);
       if (Convert.ToInt32(objPL.isSuccess) == 1)
       {
           string strScript = "<script>";
           strScript += "alert('Password Changed');";
       }
       else
       {
           Label2.Visible = true;
       }

   }


谁能建议我?


can any one suggest me??

推荐答案

检查以下内容:
check this:
if(session[USERNAME]!=null)
{
//write your code here
}


并且如果label3的可见默认值设置为false,则在回发时,您不会将其设置为true!
当您发现这种错误时,这意味着您需要休息,因为您没有足够的注意力!这来给我太多次了!:)


and if label3 visible default value set to false, at post back, you don''t set it to true!
when you find this kind of error it means you need some rest, because you don''t have enough focus! this came to me too many times!:)


对象引用未设置为对象的实例.
当您尝试使用属性或调用对象的方法为null时,会发生此错误.更多详细信息:此处 [.ToString()方法之前对其进行处理.检查它是否不为null,然后仅使用该方法.专门用于会话,应该始终进行NULL检查.
object referance is not set to an instance of an object..
This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

Based on above code and line, as others said, you need to handle Session["USERNAME"] before using it''s .ToString() method. Check if it''s not null and then only use the method. Specifically for sessions, you should always have NULL check.


此会话不存在
this session not exist
Session["USERNAME"]



使用



use

Session["LoginName"]


这篇关于谁能解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆