web窗体-System.NullReferenceException: 未将对象引用设置到对象的实例。

问题描述

System.NullReferenceException: 未将对象引用设置到对象的实例。

错误的问题!

未将对象引用设置到对象的实例。

说明: 执行当前 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();
}

}

时间: 2024-08-08 15:56:16

web窗体-System.NullReferenceException: 未将对象引用设置到对象的实例。的相关文章

Silverlight使用时,从工具箱拖拉控件到设计窗体时,抛出异常,System.NullReferenceException 未将对象引用设置到对象的实例。

问题描述 System.NullReferenceException未将对象引用设置到对象的实例.在Microsoft.Windows.Design.Platform.SilverlightMetadataContext.SilverlightXamlExtensionImplementations.<GetXmlNamespaceCompatibilityMappings>d__8.MoveNext()在MS.Internal.Design.Metadata.ReflectionProjec

救急问题:System.NullReferenceException: 未将对象引用设置到对象的实例,调式正常,IIS执行却出错!

问题描述 System.NullReferenceException:未将对象引用设置到对象的实例.protectedvoidPage_Load(objectsender,EventArgse){Manage.LogOut();Response.Redirect("Login.aspx");}LogOut()为:Static方法,VS2005调试执行的时候没有任何问题,显示为http://localhost:30988/my.webIIS执行的时候显示为http://localhost

错误解决:System.NullReferenceException: 未将对象引用设置到对象的实例

在ASP.NET开发中,遇到System.NullReferenceException: 未将对象引用设置到对象的实例的错误提示,解决方法如下:       (1)所设置的变量为空值或没有取到值,一般出现在传递参数的时候出现这个问题,也会在使用datagrid或gridview或datalist等数据控件时出现. (2)控件名称与codebehind里面的没有对应 (3)未用new初始化对象 (4)在程序中所引用的控件不存在 解决方法: (1)使用try..catch...finally捕捉错误

“ResolveAssemblyReference”任务意外失败。System.NullReferenceException: 未将对象引用设置到对象的实例。

问题描述 "ResolveAssemblyReference"任务意外失败.System.NullReferenceException:未将对象引用设置到对象的实例. 解决方案 解决方案二:你这也太笼统了.贴出出问题的代码啊.这个只能判断出现了null值,你却引用他的属性或方法.所以报这个错.

System.NullReferenceException: 未将对象引用设置到对象的实例

问题描述 报错:SqlConnectionconn=newSqlConnection();行105:行106:conn.ConnectionString=ConfigurationManager.ConnectionStrings["connectString"].ToString();行107:行108:源文件:d:OA数据备份20101217OA数据备份20101217OA8000OAsystemadminttAddNews.aspx.cs行:106堆栈跟踪:[NullRefere

上传服务器后出现System.NullReferenceException: 未将对象引用设置到对象的实例。

问题描述 如题[NullReferenceException:未将对象引用设置到对象的实例.]TopWin.WebUI.game._3jymdd.Page_Load(Objectsender,EventArgse)ine:topwincmswebuigame3jymdd.aspx.cs:80System.Web.UI.Control.OnLoad(EventArgse)+67System.Web.UI.Control.LoadRecursive()+35System.Web.UI.Page.Pr

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。请问我哪里弄错啦 为什么一点击登录就出错

问题描述 web.config代码<?xmlversion="1.0"?><configuration><system.web><compilationdebug="true"targetFramework="4.0"/></system.web><appSettings><addkey="SqlConnStrName"value="ser

网站上线正常运行一天后,报错System.NullReferenceException: 未将对象引用设置到对象的实例

问题描述 报错信息:我要是把<%#Edu.Common.HelpCommon.GetSubString(Eval("Titles").ToString(),17)%>改写成<%#Eval("Titles")%>错误行就会显示下一个<%#Edu.Common.HelpCommon.GetSubString(Eval("Titles").ToString(),17)%>调用方法如下:publicstaticstri

急救·一直好好的突然一下就不行了· [NullReferenceException: 未将对象引用设置到对象的实例

问题描述 未将对象引用设置到对象的实例.说明:执行当前Web请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息.异常详细信息:System.NullReferenceException:未将对象引用设置到对象的实例.源错误:[没有相关的源行]源文件:c:WindowsMicrosoft.NETFrameworkv4.0.30319TemporaryASP.NETFilesrootac64075ed0fba290App_Web_eyddlggb.0