我试图在页面加载时将两个标签的文本设置为随机数。这段代码
Random random = new Random();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LINE 22 Label12.Text = random.Next(99).ToString();
LINE 23 Label13.Text = random.Next(999).ToString();
}
foreach (string s in scr1.Style.Keys)
{
Response.Write(s + ",");
}
}
...
在本地主机上工作,但在我的服务器上运行时会抛出 NullReferenceException。
堆栈跟踪:
[NullReferenceException:对象引用未设置为对象的实例。] .apps。.Page_Load(Object sender, EventArgs e) in C:\Users** \Documents\Visual Studio 2010\Projects* *** \apps* *.aspx.cs:22 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp , 对象 o, 对象 t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI .Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint) +2207