Copied to clipboard

Flag this post as spam?

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


  • Zakhar 171 posts 397 karma points
    Jul 02, 2012 @ 12:30
    Zakhar
    0

    Customizing standard Umbraco login control

    I'm adding a login form on my page with this macro:

    <asp:Login ID="Login1" runat="server" DestinationPageUrl="/"></asp:Login>

    Is it possible to customize it? I need to change labels, text and add some css classes.

    Also is it possible to add returnUrl parameter somehow, so user will be redirected to the referrer page after login?

    Thanks

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 02, 2012 @ 13:56
    Michael Latouche
    0

    Hi Zakhar,

    Normally there is a lot you can do on the control itself. If you open it in design view in Visual Studio and open the Property Window, you will be able to change quite a lot of things regarding style, labels etc.

    If this is not enough and you want to customize it more, you can actually transform the control into a template (if I remember correctly, click in the upper right corner of the control and you should see a menu from which you can turn the control into a template), where you then have full control on labels etc.

    Hope this helps you get started.

    Cheers,

    Michael.

  • John C Scott 473 posts 1183 karma points
    Jul 02, 2012 @ 14:05
    John C Scott
    0

     

    Yes this can all be customised. 

    Here's an example from a page I am working on right now:

    <asp:Login RenderOuterTable="false" ID="ctlLogin" runat="server" OnLoginError="OnLoginError" onloggedin="OnLoggedIn" RememberMeSet="True" VisibleWhenLoggedIn="False">
        <LayoutTemplate>
            <div id="login">
                <dl class="form">
                    <dt>
                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label></dt>
                    <dd>
                        <asp:TextBox ID="UserName" CssClass="required" ToolTip="Enter username" runat="server"></asp:TextBox>
                    </dd>
                    <dt>
                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                    </dt>
                    <dd>
                        <asp:TextBox ID="Password" CssClass="required" ToolTip="Enter password" runat="server" TextMode="Password"></asp:TextBox>
                    </dd>
                    <dt></dt>

                    <dd>
                        <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" />
                    </dd>
                </dl>
            </div>
            
        </LayoutTemplate>
    </asp:Login> 

    I took this example from the source of nForum where there are far more details in the source code 
    http://nforum.codeplex.com/SourceControl/list/changesets 

    The above is set up in a user control for me called login.ascx and in the .cs code behind file I have:

        public partial class Login : System.Web.UI.UserControl
        {
            protected void OnLoginError(object sender, EventArgs e) {}
    protected void OnLoggedIn(object sender, EventArgs e) {
                Response.Redirect("/");
     }
        } 

    As you can see this doesn't do very much, but you could easily add more code to the response.redirect.

     

  • Zakhar 171 posts 397 karma points
    Jul 02, 2012 @ 15:33
    Zakhar
    0

    @Michael, thanks, but how do I open this control? It's not my control but standard umbraco one. I didn't create it and I don't have it in my usercontrols folder. I can't find it anywhere. Have a look at this tutorial if it's not clear what I mean: http://www.mortenbock.dk/blog/2009/04/01/setting-up-membership-in-umbraco.aspx .

    @John thank you too, but that means I have to create my own login control instead of using standard umbraco login control. Then I will have to handle all user authentication myself. Apparently I will have to do it, but I thought may be it's easier to customize existing control than create new one. Do you share you code for authenticating user?

     

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 02, 2012 @ 15:48
    Michael Latouche
    0

    Hi Zakhar,

    If you refer to your line

    <asp:Login ID="Login1" runat="server" DestinationPageUrl="/"></asp:Login>

    this is not Umbraco custom control/macro but a Microsoft ASP.Net Membership Provider default user control for login.

    So, if you have added that control on one of your template, opening the template in Visual Studio should display the user control, and from there you should have access to the control's properties in the VS properties window.

    Does that make sense, or am I missing something maybe? Otherwize, can you maybe send the full HTML/script surrounding that line?

    Cheers,

    Michael.

  • Zakhar 171 posts 397 karma points
    Jul 02, 2012 @ 17:01
    Zakhar
    0

    Thanks Michael, you are right, I didn't know that I can open it like this. I will try to find out how to do redirect from such control, may be I can inherit from it or something.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jul 02, 2012 @ 17:12
    Michael Latouche
    0

    Hi Zakhar,

    There should be a property "PostBackUrl" or "SuccessLoginUrl" or something like that that you can set. If that Url must be dynamic, like the referrer, you should be able to specify it in your codebehind.

    Another solution might be to register an "OnLoggedIn" event where you do the redirect, but I do not think you need to create a new control inheriting from it.

    Cheers,

    Michael.

  • Zakhar 171 posts 397 karma points
    Jul 14, 2012 @ 13:37
    Zakhar
    0

    Thanks for help guys, but I ended up implementing my own login control, as I couldn't overcome some other restrictions of standard one. It wasn't that difficult at the end of the day.

  • 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