私はいくつかのコントロールを追加しているサイトマスターを持っています.1つはプログラムで更新されるラベルです。サイト マスターでスコープがどのように機能するかについての私の理解が間違っている可能性があるため、2 番目の例でオブジェクトを参照できない理由がわかりません。どんな援助でも大歓迎です!
この「ClubName」ラベルは意図したとおりに機能します
<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.