错误的问题!
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 40:
行 41: Application.Lock();
行 42: ((Panel)Application["char"]).Controls.AddAt(0,lbr);
行 43: ((Panel)Application["char"]).Controls.AddAt(0,_words);
行 44: ((Panel)Application["char"]).Controls.AddAt(0,_dt);
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class 简易聊天室 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uid"] == null) {
Response.Redirect("聊天室登录.aspx");
}
if (Application["chat"] == null) {
Application["chat"] = new Panel();
}
Panel1.Controls.Add((Panel)Application["chat"]);
}
protected void Button2_Click(object sender, EventArgs e)
{
Session.Remove("uid");
Response.Redirect("聊天室登录.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
Label _uid = new Label();
_uid.Text = Session["uid"].ToString();
Label _dt = new Label();
_dt.Text = DateTime.Now.ToLongTimeString();
Label _words = new Label();
_words.Text = TextBox1.Text;
Literal lbr=new Literal();
lbr.Text="<br/>";
Application.Lock();
((Panel)Application["char"]).Controls.AddAt(0,lbr);
((Panel)Application["char"]).Controls.AddAt(0,_words);
((Panel)Application["char"]).Controls.AddAt(0,_dt);
((Panel)Application["char"]).Controls.AddAt(0,_uid);
Application.UnLock();
}
}