Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ds 191 posts 223 karma points
    Sep 08, 2011 @ 07:40
    ds
    0

    Multilingual LoginStatus control

    I try to set Loginstatus logintext by using dictionary item via code behind. I created a macro in master template using a usercontrol like in the following.

    <asp:LoginView ID="LoginView1" runat="server">
        <AnonymousTemplate>
            <span class="input"><umbraco:Item field="#You are not logged-in:" runat="server"></umbraco:Item> <asp:LoginStatus ID="LoginStatus1" runat="server" /> <umbraco:Item field="#Or" runat="server"></umbraco:Item> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="/Register.aspx"><umbraco:Item field="#Register" runat="server"></umbraco:Item></asp:HyperLink></span>
        </AnonymousTemplate>
        <LoggedInTemplate>
            <span class="input"><umbraco:Item field="#Hello" runat="server"></umbraco:Item> <asp:LoginName ID="LoginName1" runat="server" /> <asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="/ControlPanel.aspx"><umbraco:Item field="#Control Panel" runat="server"></umbraco:Item></asp:HyperLink> | <asp:LoginStatus ID="LoginStatus2" runat="server" /></span>
        </LoggedInTemplate>
    </asp:LoginView>

    in code-behind

            protected void Page_Load(object sender, EventArgs e)
            {
                var ls = (LoginStatus)LoginView1.FindControl("LoginStatus1");
                ls.LoginText = umbraco.library.GetDictionaryItem("Login");
            }

    So far so good, I am able to change loginstatus text. Moreover on login page, if you would ever try to log-in, I get

    Object reference not set to an instance of an object.

  • Michael Latouche 504 posts 819 karma points MVP 5x c-trib
    Sep 08, 2011 @ 08:30
    Michael Latouche
    0

    Hello,

    This is because, after you login, the control wille display/ the LoggedInTemplate, and not the AnonymousTemplate. So the LoginStatus1 control, which resides in the AnonymousTemplate, is not availabl in login mode.

    I guess something like the following should solve your issue:

    protectedvoidPage_Load(object sender,EventArgs e)
           
    {
               
    var ls =LoginView1.FindControl("LoginStatus1") as LoginStatus;
    if (ls != null)
                ls
    .LoginText= umbraco.library.GetDictionaryItem("Login");
           
    }

    Cheers,

    Michael.

  • ds 191 posts 223 karma points
    Sep 08, 2011 @ 08:59
    ds
    0

    Hi Michael,

    This is how I made it work. Thanks for the feedback

            protected void Page_Load(object sender, EventArgs e)
            {
                var ls = (LoginStatus)LoginView1.FindControl("LoginStatus1");
                var ls2 = (LoginStatus)LoginView1.FindControl("LoginStatus2");
                if (ls != null)
                {
                    ls.LoginText = umbraco.library.GetDictionaryItem("Login");
                }

                if (ls2 != null)
                {
                    ls2.LogoutText = umbraco.library.GetDictionaryItem("LogOut");
                }
            }
  • Michael Latouche 504 posts 819 karma points MVP 5x c-trib
    Sep 08, 2011 @ 11:22
    Michael Latouche
    0

    The key was indedd the check in  null ;-)

    Glad you got it working!

    Cheers,

    Michael.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies