“/bgzdh”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 36:  if (this.IsPostBack)
行 37:  return;
行 38:  if( this.Session["Flag"].ToString() == "1" )
行 39:  {
行 40:  cxtj = "01";
 源文件: c:\inetpub\wwwroot\bgzdh\w_mainmeun_wqz.aspx.cs    行: 38 堆栈跟踪: 
[NullReferenceException: 未将对象引用设置到对象的实例。]
   bgzdh.W_mainmeun_wqz.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\bgzdh\w_mainmeun_wqz.aspx.cs:38
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain() 
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573

解决方案 »

  1.   

    this.Session["Flag"] 返了回null吧
      

  2.   

    "this.Session["Flag"] 返了回null"改了之后返回这样的错误
    “/bgzdh”应用程序中的服务器错误。
    --------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 36:  if (this.IsPostBack)
    行 37:  return;
    行 38:  if( this.Session["Flag"].ToString() == "null" )
    行 39:  {
    行 40:  cxtj = "01";
     源文件: c:\inetpub\wwwroot\bgzdh\w_mainmeun_wqz.aspx.cs    行: 38 堆栈跟踪: 
    [NullReferenceException: 未将对象引用设置到对象的实例。]
       bgzdh.W_mainmeun_wqz.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\bgzdh\w_mainmeun_wqz.aspx.cs:38
       System.Web.UI.Control.OnLoad(EventArgs e)
       System.Web.UI.Control.LoadRecursive()
       System.Web.UI.Page.ProcessRequestMain() 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
      

  3.   

    if (this.IsPostBack)
    return; 
    if( this.Session["Flag"] != null)
    {
         if (Session["Flag"].ToString() == "1")
    {
    //这里再加入代码
    }
    }
      

  4.   

    你误会jinjazz的意思了
    先要判断Session不为空你该这么写
    if(Session["Flag"]!=null)
    {
        if(Session["Flag"].ToString()=="1")
        {
         //你的操作
         }
    }
      

  5.   

    this.Session["Flag"]去用时判断一下
    if(this.Session["Flag"]!=null)
    {
    }
      

  6.   

    if(Session["Flag"]!=null)
    {
        if(Session["Flag"].ToString()=="1")
        {
        
         }
    }
      

  7.   

    出错代码如下: if( this.Session["Flag"].ToString() == "1" )
    {
    cxtj = "01";
    // Label2.Text = " 发文管理 " ;
    Image2.ImageUrl = "images/a1.jpg" ;
    }
    else
    {
    cxtj = this.Session["PartId"].ToString().Trim() ;
    cxtj = cxtj + "" ;

    if(cxtj.Trim() == "01")
    {
                        Image2.ImageUrl = "images/a1.jpg" ;
    }
    if(cxtj.Trim() == "02")
    {
                        Image2.ImageUrl = "images/a2.jpg" ;
    }
    if(cxtj.Trim() == "03")
    {
    Image2.ImageUrl = "images/a3.jpg" ;
    }
    if(cxtj == "04")
     {
     Image2.ImageUrl = "images/a4.jpg" ;
     }
    if(cxtj == "05")
    {
    Image2.ImageUrl = "images/a5.jpg" ;
    }
    if(cxtj == "06")
    {
    Image2.ImageUrl = "images/a6.jpg" ;
    }
    if(cxtj == "08")
    {
    Image2.ImageUrl = "images/a9.jpg" ;
    }
    }
      

  8.   

    改了之后出现如下提示
    “/bgzdh”应用程序中的服务器错误。
    --------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 81:  }
    行 82:  }
    行 83:  string name = this.Session["username"].ToString().Trim() ;
    行 84:  name = name + "" ;
    行 85:  Label1.Text = " 欢迎你:" + name.Trim() ;
     源文件: c:\inetpub\wwwroot\bgzdh\w_mainmeun_wqz.aspx.cs    行: 83 堆栈跟踪: 
    [NullReferenceException: 未将对象引用设置到对象的实例。]
       bgzdh.W_mainmeun_wqz.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\bgzdh\w_mainmeun_wqz.aspx.cs:83
       System.Web.UI.Control.OnLoad(EventArgs e)
       System.Web.UI.Control.LoadRecursive()
       System.Web.UI.Page.ProcessRequestMain() 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
      

  9.   

    这是出错的程序段
    if( this.Session["Flag"].ToString() == "1" )
    {
    cxtj = "01";
    // Label2.Text = " 发文管理 " ;
    Image2.ImageUrl = "images/a1.jpg" ;
    }
    else
    {
    cxtj = this.Session["PartId"].ToString().Trim() ;
    cxtj = cxtj + "" ;

    if(cxtj.Trim() == "01")
    {
    Image2.ImageUrl = "images/a1.jpg" ;
    }
    if(cxtj.Trim() == "02")
    {
    Image2.ImageUrl = "images/a2.jpg" ;
    }
    if(cxtj.Trim() == "03")
    {
    Image2.ImageUrl = "images/a3.jpg" ;
    }
    if(cxtj == "04")
    {
    Image2.ImageUrl = "images/a4.jpg" ;
    }
    if(cxtj == "05")
    {
    Image2.ImageUrl = "images/a5.jpg" ;
    }
    if(cxtj == "06")
    {
    Image2.ImageUrl = "images/a6.jpg" ;
    }
    if(cxtj == "08")
    {
    Image2.ImageUrl = "images/a9.jpg" ;
    }
    }
      

  10.   

    2个地方有可能出错:
    一个就是上面兄弟们说的if( this.Session["Flag"].ToString() == "1" )
    之前要判断是否为空。另一个地方就是这里:
    行 83:  string name = this.Session["username"].ToString().Trim() ;
    同样要在trim之前判断是否为空.
      

  11.   

    谢谢各位改了之后好多了现在还提示:
    “/bgzdh”应用程序中的服务器错误。
    未将对象引用设置到对象的实例。
      

  12.   

    这个地方判断了!!!没效果
    行 83:  string name = this.Session["username"].ToString().Trim() ;
    同样要在trim之前判断是否为空.
    还是提示这个
    “/bgzdh”应用程序中的服务器错误。
    未将对象引用设置到对象的实例。
      

  13.   

    =。= 错误原因很简单 null 不能 ToString()呀
      

  14.   

    有没有人在呀?????
    我的问题还没解决呢!!!!
    其实我在这个出错页面下做一个TREEVIEW可是死活不显示