Controls innerhalb von LoginView ansprechen

Hallo,

manchmal sieht man den Wald vor lauter Bäumen nicht ;). Nun suchte ich eine Methode, um auf die Controls innerhalb eines asp:LoginView Controls zuzugreifen.

Fündig geworden bin ich hier, und ich nutze die FindControl Methode so oft …, manchmal ärgerlich.

Ich zeige es einmal anhand des Beispiels von Thomas.

asp.net

<asp:loginview id="LVBla" runat="server">
     <anonymoustemplate>
         <asp:label ID="AnonymousLabel" runat="server"></asp:label>
     </anonymoustemplate>
</asp:loginview>

c#

 
protected void Page_Load(object sender, EventArgs e)
{
    Label anonymousLabel = (Label)LVBla.FindControl("AnonymousLabel");
 
    if (anonymousLabel != null) {
        anonymousLabel.Text = DateTime.Now.ToString();
    }
}

Und das ganze nochmal in VB.NET

vb.net

Dim anonymousLabel As Label = CType(Me.LoginView1.FindControl("AnonymousLabel"), Label)
 
If Not (anonymousLabel Is Nothing) Then
    anonymousLabel.Text = DateTime.Now.ToString()
End If

Related Posts: