Problems with Login Custom Control

Posted by Community Admin on 04-Aug-2018 16:26

Problems with Login Custom Control

All Replies

Posted by Community Admin on 02-Dec-2011 00:00

First, let me say that I really like Sitefinity.  There are however, a number of very basic things are really lacking.  The frontend user account management widgets kinda suck.  Just about every website I visit has functionality that allows a user to register, login, retreive or reset thier password, change thier password, etc.  SF only includes "Login", "Login name", and "Log in / log out button" widgets.  To make matters worse, there's something broken with the designer that prevents the "LoggedInLayoutTemplatePath" and "LoggedOutLayoutTemplatePath" settings from being persisted and from what I can tell it's been broken for a long time. 

So the only real option is to roll my own which should be simple enough.  Should be, but I've run into a strange problem.  Below are my template mark up and control code:

Template:

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="sf" %>
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
 <AnonymousTemplate>
  <asp:HyperLink ID="LoginLink" runat="server" NavigateUrl="~/login" CssClass="loginContainerLoginLink">Log In</asp:HyperLink>
 </AnonymousTemplate>
 <LoggedInTemplate>
  <ul id="loginStatus">
   <li class="loginContainerYourAccount">
    <asp:LinkButton ID="YourAccountLinkBtn" runat="server" Text="Your Account" CssClass="loginContainerYourAccountLink" />
   </li>
   <li class="loginContainerLogout">
    <asp:LinkButton ID="LogOutLinkBtn" runat="server" Text="Log Out" CssClass="loginContainerLogoutLink" />
   </li>
  </ul>
 </LoggedInTemplate>
</asp:LoginView>

Code:
using Telerik.Sitefinity.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Security;
using System.Web.UI;
namespace SitefinityWebApp.CustomControls
public class LoginStatusWidget : SimpleView
#region Properties
protected override string LayoutTemplateName
get return "SitefinityWebApp.CustomControls.Resources.Views.LoginStatusWidget.ascx";
#endregion
protected override void InitializeControls(GenericContainer container)
EnsureChildControls();
LinkButton logOutLinkBtn = base.Container.GetControl<LinkButton>("LogOutLinkBtn", false); ;
LinkButton yourAccountLinkBtn = base.Container.GetControl<LinkButton>("YourAccountLinkBtn", false);
if(logOutLinkBtn != null)
logOutLinkBtn.Click += new System.EventHandler(OnLogOutLinkBtnClick);
if (yourAccountLinkBtn != null)
yourAccountLinkBtn.Click += new System.EventHandler(OnYourAccountLinkBtnClick);
void OnYourAccountLinkBtnClick(object sender, System.EventArgs e)
this.Page.Response.Redirect("~/user/your-account");
void OnLogOutLinkBtnClick(object sender, System.EventArgs e)
SecurityManager.Logout();
SecurityManager.DeleteAuthCookies();
this.Page.Response.Redirect("~/");

The problem is that
base.Container.GetControl<LinkButton>("LogOutLinkBtn", false);
and base.Container.GetControl<LinkButton>("YourAccountLinkBtn", false);

always return null.  I've tried looking for the control a number ways but the result is always null.  Is there something different I need to do to find control in a LoginView / AnonymousTemplate / LoggedInTemplate?

Thanks--Steve

Posted by Community Admin on 03-Dec-2011 00:00

Well, I've spent hours of trying to get this to work with absolutely no progress.  Googling turns up a large number of posts on the subject an the common strategy is to find first the LoginView control and then call the LoginView's FindControl method.  The problem is that I can't find the LoginView.

Ironically, if I move the controls outside of <LoggedInTemplate></ LoggedInTemplate> tags I can find the controls with no problem.

 Does anyone have any ideas here?

Thanks--Steve

Posted by Community Admin on 03-Dec-2011 00:00

Just a quick post to close this out in case someone else runs into the same type of problem.  This is a case where creating a custom control that inherits from SimpleView is a bad idea.  I spent hours trying to make this work without success.  I finally decided to make this into a standard ASP.net WebUserControl and had it coded, working, and registered in 15 minutes from start to finish.

--Steve

Posted by Community Admin on 22-Feb-2013 00:00

Hi, do you have a post where you explain how you solved it. I am using my own web user controls with Login, LoginView and Register.  

Currently I have the problem that the LoginView control is not refreshed. This is because the page itself is cached. Disable the cache for the page solves the problem, but somehow I think that it is not wise. Since the LoginView appears on the header of each page, this would mean I cannot cache a single page and thus creating a performance leak. How do you handle your LoginView control?

This thread is closed