按网页http://topic.csdn.net/t/20031228/11/2610749.html中所说的方法在两个页面中进行传值
Session["entID"] = TextBox1.Text
但是在另一页面中引用时
TextBox2.Text = Session["entID"].ToString();
却无法传值,提示System.NullReferenceException: 未将对象引用设置到对象的实例,请问哪里出错,该如何改正?谢谢!

解决方案 »

  1.   

    使用Session对象保存用户登录名的代码如下:     Session.Remove("UserName"); 
          Session["UserName"] = txtName.Text; 
           Response.Redirect("NavigatePage.aspx"); 在NavigatePage.aspx页面中,将Session对象的值显示在界面上,其代码如下:
       if (Session["UserName"] == null) 
         { 
           Response.Redirect("Default.aspx"); 
         } 
           else 
         { 
           Label1.Text =Session["UserName"].ToString(); 
         } 
      

  2.   

    您是不是说前面加上条Session.Remove("UserName")就行?
    我试了下,是一样的情况
      

  3.   

     if (this.Code.Value.Trim() == Session["MyCode"].ToString())
            {
                Ubo.UserUid = txtUserUid.Text.Trim();
                Ubo.UserPwd  = txtUserPwd.Text.Trim();
                if (data.checkLogin(Ubo.UserUid, Ubo.UserPwd) > 0)
                {
                    ViewState["UID"] = Ubo.UserUid;
                    Session["UID"] = Ubo.UserUid;
                    this.Page.RegisterStartupScript("Tip", "<script>alert('尊敬的用户『" + this.txtUserUid.Text + "』恭喜您登录成功!')</script>");
                    lblGetUserName.Visible = true;
                    lnkUserInfo.Visible = true;
                    lblGetUserName.Text = "欢迎您『" + ViewState["UID"].ToString() + "』成为本站会员";
                    txtUserUid.Text = "";
                    Code.Value = "";
                    return;
                }
                else
                {
                    this.Page.RegisterStartupScript("Tip", "<script>alert('对不起,您输入的用户名或密码不正确!')</script>");
                    return;
                }
            }
            else
            {
                this.Page.RegisterStartupScript("MsgOnlyAlert", "<script>alert('对不起,验证码输入不正确!')</script>");
                return;
            }
      

  4.   

    你的 TextBox1.Text有值吗?
    System.NullReferenceException说你的内存问题 
    应该没有问题啊 
      

  5.   

    Google到http://topic.csdn.net/u/20090324/21/6e989fc6-d432-4086-9e92-f1cbbb40320a.html
    说要[WebMethod(EnableSession = true)] 
    我看不懂,请问,这是怎么回事?
      

  6.   

    Session["entID"].ToString();   有问题,判断一下 session["entID"] != null
      

  7.   

    引用.....ASP.NET Web Services默认禁止Session
    如果一定要使用Session必须先启用...首先修改web.config中 <sessionState>的mode值为On,然后还要为方法启用Session
    即[WebMethod(EnableSession=True)]
      

  8.   

    别人那是在Web Service中使用Session的方法。
    如果你真的要在Web Service中使用回话的话,还要设置其他的东西
      

  9.   

    你这肯定是Session["entID"]没有取到的问题
      

  10.   

    如果Session["entID"]没有取到,那应该如何修改?
      

  11.   


    session.add("entID", TextBox1.Text)
      

  12.   

    在第二个页面,你先判断一下SESSION中是否有值,如果有值你在赋值.
    if (Session["entID"]!=null)
    {
         TextBox2.Text =Session["entID"].ToString(); 
    }