我有以下功能和标签,我想将标签设置为abc。
<asp:Label ID="title" runat="server"></asp:Label>
protected void setTitle()
{
title.Text = "abc";
}
当我执行该功能时,在关联行我得到了这个:
对象引用未设置为对象的实例。
有人知道为什么吗?
LATER EDIT:请参阅下面的评论
我发现了这个建议但它仍然无效。它引发了同样的异常。为什么呢?
protected void Page_Load(object sender, EventArgs e)
{
Page.LoadComplete += new EventHandler(Page_LoadComplete);
}
void Page_LoadComplete(object sender, EventArgs e)
{
setTitle();
}
完成aspx
<%@ Page Language="C#" AutoEventWireup="true" Inherits="......." CodeBehind="....aspx.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="style/style.css"/>
</head>
<body>
<div id="left"><img src="Imagini/Left_01.jpg" alt="" /></div>
<form id="form1" runat="server">
<div id="left_edge"><img src="Imagini/LeftEdge.jpg" alt="" /></div>
<div id="questions">
<div id="top"></div>
<div class="clear"></div>
<div class="row">
<h1>
<asp:Label ID="title" runat="server" Text=""></asp:Label>
</h1>
</div>
<div class="clear"></div>
</div>
<div id="right_edge"><img src="Imagini/rightedge_04.jpg" alt="" /></div>
</form>
<div id="right"><img src="Imagini/right_05.jpg" alt="" /></div>
</body>
</html>