Okay so I'm quite new to ASP.NET and the MasterPage concept and there's an error I just can't figure out.
This is a part of my default.aspx:
<asp:Content ID="ContentLoginContent" ContentPlaceHolderID="LoginContentPlaceHolder" runat="server">
<div id="ContentLoginDiv">
You've got <asp:Label ID="MemberCreditLabel" runat="server" Text="0"></asp:Label> credits.
</div>
This is the relevant part of my default.aspx.cs:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
if (User.IsInRole("Authenticated"))
{
MemberCreditLabel.Text = "hello ";
}
}
}
I get a Nullref exception on MemberCreditLabel. It gets detected with intelliSense. I think the problem could be that the ContentPlaceHolder "ContentLoginContent" only shows when logged in. This is a part of my MasterPage:
<asp:LoginView ID="MemberLoginView" runat="server">
<AnonymousTemplate>
<asp:Login ID="LogInBox" runat="server" Height="137px" style="margin-left: 0px"
Width="16px">
</asp:Login>
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <asp:LoginName ID="MemberLoginName" runat="server" /> !
<asp:LoginStatus ID="MemberLoginStatus" runat="server" />
<asp:ContentPlaceHolder ID="LoginContentPlaceHolder" runat="server">
//Is this the problem?
</asp:ContentPlaceHolder>
</LoggedInTemplate>
</asp:LoginView>
What I want to do is to show a credit amount stored in a database. The function for retreiving the data I want works. I take the user name of the currently logged in user and want to get the credit amount associated with the user. But this strange error with the label halts me completely.. It's probably got to do with a concept of MasterPages that I haven't stumbled across yet. Any ideas?