我有一个站点管理员,我正在添加一些控件,其中一个是一个以编程方式更新的标签。我不确定为什么在第二个示例中我无法引用该对象,如果我对站点主机中范围如何工作的理解是错误的。任何帮助将不胜感激!
这个“俱乐部名称”标签按预期工作
<div class="main">
<asp:Label ID="ClubName" runat="server"></asp:Label>
</div>
虽然这个没有(对象引用未设置为对象的实例)
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
<asp:Label ID="ClubName" runat="server" Text="Label"></asp:Label>
</LoggedInTemplate>
</asp:LoginView>
我的代码背后的代码很简单
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
NameClub.Text = "hello";
}
和异常错误:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.