Search code examples
c#asp.netloginview

LoginView control question!


I have a button in that control. How do i reach it programmatically.. I cant reach it by pressing the buttons ID in the code partial class code file.

          if (HttpContext.Current.User.IsInRole("Administrator") || HttpContext.Current.User.IsInRole("Moderator"))
        {
            Button button = (Button)LoginView1.FindControl("DeleteThread");

Solution

  • from here

    For the LoginView control, when being added onto a page, at a certain time, only one Template (anonymous or loggedIn ) is applied on the Control instance, so at that time, we can only retrieve the reference of those controls in the active template( can't access those in the non-active template). So you can first determine whether the user has been authenticated or not and then use the LoginView.FindControl( stringId) together with the sub control's ID to retrieve the control reference.