Label l = (Label)userpanel2.FindControl("lbUser");
l.Text = "abc";

解决方案 »

  1.   

    好像还是不行啊!还是提示System.NullReferenceException: 未将对象引用设置到对象的实例。
      

  2.   

    where is this userpanel2? does your code-behind class haveprotected Panel userpanel2;???
      

  3.   

    在C#代码中定义了userpanel
    代码如下:
    public Panel userpanel1,userpanel2;
    在 userpanel1中放了二个文本框和一个登录按钮,
    在 userpanel2中放了一个Label和一个登出按钮。
    当Session["user"]为空时,userpanel1.Visible=true,用户可输入用户名和密码登录。
    否则,userpanel2.Visible = true, Label中显示用户名,点登出按钮,Session.Clear()但总提示System.NullReferenceException: 未将对象引用设置到对象的实例。
    不知道是哪错了!