+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Login control inside loginview control

Login control inside loginview control

10 posts, 0 answered
  1. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    15 Feb 2010
    Link to this post
    Hello,

    I created a user control and placed Loginview control on it. Then I added Login control to the anonymous template. Everything works fine on public side.
    How can I edit the properties of the Login control (inside of the Loginview control) in the page edit mode? I tried to expose the login control as a public property, but it didn't work
    ( _login =(Login) this.LoginView1.FindControl("Login1");)

    Can you plz help me on this

    Thanks & regards
    GV
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    15 Feb 2010
    Link to this post
    Hello GV,

    The code you posted shows that you are looking for the control, but you need to expose a public property of the Login control to access its porperties

    sample code

    public Login Login
    {
        get
        {
            return this.Login1;
        }
        set
        {
            this.Login1 = value;
        }
    }


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    15 Feb 2010
    Link to this post
    Thanks Ivan,

    I understand that, but the login control is inside the Loginview control. How can I expose that?
    <asp:LoginView ID="LoginView1" runat="server">
        <AnonymousTemplate>
            <asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Home/MemberHome.aspx"
                OnLoggedIn="Login1_LoggedIn" OnLoggingIn="Login1_LoggingIn" EnableTheming="False"
                VisibleWhenLoggedIn="true">
                <LayoutTemplate>
                    <h2>
                        Already a member?</h2>
                    <p>
                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
                            ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="ctl00$Login1">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                        <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                            ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="ctl00$Login1">*</asp:RequiredFieldValidator>
                    </p>
                    <p>
                        <asp:HyperLink ID="hlnkForgotpwd" runat="server" Text="Forgot your password?" NavigateUrl="~/forgotpassword.aspx"></asp:HyperLink>
                    </p>
                    <p>
                        <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                    </p>
                    <p>
                        <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="ctl00$Login1" />
                    </p>
                </LayoutTemplate>
            </asp:Login>
        </AnonymousTemplate>
        <LoggedInTemplate>
            You're logged in!!!
        </LoggedInTemplate>
    </asp:LoginView>
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Feb 2010
    Link to this post
    Hello GV,

    The Login control is not accessible with the find control method because it is added to the markup of the AnonymousTemplate. In this case what you can do would be to add a property of type login to your user control. Then on page load check if the LoginView template instantiated contains a Login control if yes assign this control the value of the property:
    protected void Page_Load()
    {
        Login login = (Login)LoginView1.Controls[0].FindControl("Login1");
        if (login != null)
        {
            login = this.loginControl;
        }
    }
     
    public Login LoginControl
    {
        get
        {
            return this.loginControl;
        }
        set
        {
            this.loginControl = value;
        }
    }
    private Login loginControl;

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    15 Feb 2010
    Link to this post
    Thanks for the quick reply.
    I tried the code, but the login control still shows None and not allowing me to edit its properties. May be because the admin is logged in for editing the page and the control is in anonymous template. What are your thoughts on this?

    Thanks & regards
    GV
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Feb 2010
    Link to this post
    Hello GV,

    It shows none because the this.loginControl is not instantiated. Try something like this:

    public Login LoginControl
    {
        get
        {
            if (this.loginControl == null)
                loginControl = new Login();
            return this.loginControl;
        }
        set
        {
            this.loginControl = value;
        }
    }
    private Login loginControl;

    All the best,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    15 Feb 2010
    Link to this post
    Thank you for the code. Even though I'm able to edit the login control, none of the properties like DestinationPageURL, LoginFailureText etc. are getting applied to the control. The control still take its default vlaues.
    Am I missing the trick here?

    Thanks & regards
    GV
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Feb 2010
    Link to this post
    Hi GV,

    The problem is that you have already set those properties of the Login control in the markup. This is an issue of the Login control. Try declaring it simply like this:
    <asp:Login ID="Login1" runat="server" >
    </asp:Login>


    Greetings,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. GV
    GV avatar
    33 posts
    Registered:
    11 Sep 2009
    15 Feb 2010
    Link to this post
    Thanks again.
    I cannot use the control like that because i need to control the appearance of the login control with layout template. Even though I didn't set any of the prorperties in the ascx file, it is still taking those default values.

    Thanks & regards
    GV
  10. Mehdi Aliakbari
    Mehdi Aliakbari avatar
    7 posts
    Registered:
    25 May 2010
    01 Jul 2012
    Link to this post
    Hi All,
    Maybe it was too late for GV for the solution, but I'll let you know the solution for others like me that will be faced to this issue.

    Let's make it fast and simple:
    1- First of all the code should be written in OnPreRender event. Here is the clue:
    write down this line of code on every event such as OnInit, OnLoad and etc to see the only place it works is in OnPreRender:
    ...
    login.UsernameLabel = "Test";
    The reason is no other changes may occurred to our lonely Login Control after OnPreRender.

    2- Second: Radoslav has made a mistake on the following line:
    login = this.loginControl;

    This should be:
    login = this.LoginControl; //Please notify at the big L for LoginControl, You know the reason ;)
    But later you'll see this code doesn't have a chance to work because the real LoginControl still exists in parent control and it seems that LoginView control doesn't like our newly created control.

    3- Last, the final solution:

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
     
        LoginWidget login = (LoginWidget)LoginView.Controls[0].FindControl("Login");
        if (login != null)
        {
            int loginControlIndex = LoginView.Controls[0].Controls.IndexOf(login);
            LoginView.Controls[0].Controls.RemoveAt(loginControlIndex);
            LoginView.Controls[0].Controls.AddAt(loginControlIndex, this.LoginControl);
        }
    }

    This will works fine for me.

    Regards,
    Mehdi
Register for webinar
10 posts, 0 answered