[ [ [

Change the text of a Label inside a LoginView

3k Views Asked by At
<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" />,
            You're <asp:Label ID="AgeLabel" runat="server" Text="Label"> </asp:Label></span>!
        [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
    </LoggedInTemplate>
</asp:LoginView>

I want to do something like

AgeLabel.Text = Profile.GetPropertyValue("Age").ToString();

How can I do this? AgeLabel i inside a template so it looks like I can't refference it in

2

There are 2 best solutions below

0
Tim Schmelter On BEST ANSWER

Have you tried following?

<asp:Label ID="AgeLabel" runat="server" Text='<%# Profile.GetPropertyValue("Age").ToString() %>' />

Otherwise you could access the Label from Codebehind with FindControl:

Dim AgeLabel As Label = DirectCast(HeadLoginView.FindControl("AgeLabel"), Label)
0
fedotoves On

Or you can break elements apart, there is an option "Convert to template" for login control. You will have all elements as separate elements but the functionality of Login control is preserved