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

Forums / Developing with Sitefinity / [SF 5.0] What is the easy and best method to override RegistrationForm widget?

[SF 5.0] What is the easy and best method to override RegistrationForm widget?

6 posts, 0 answered
  1. mstoffel
    mstoffel avatar
    27 posts
    Registered:
    13 Jul 2005
    20 Mar 2012
    Link to this post
    Hi,

    I want insert some logic (behind code) into the RegistrationForm when the user click the button "Register".

    For example: Lookup into a external database if the user is still register. Stop the registration if exist or display a message...

    What is the best and easy method to accomplish this goal? And keep all advantage of the RegistrationForm widget like email, activation, roles...

    Thanks for your help.
  2. Bobby
    Bobby avatar
    8 posts
    Registered:
    04 Feb 2012
    26 Mar 2012
    Link to this post
    Hi Michel,

    You can create a custom control and inherit from the RegistrationForm. The registratino form has the following method that you can override,
    protected virtual void RegisterButton_Click(object sender, System.EventArgs e)

    In addition if you want to override the look and feel of the Registration Form, you can specify and different layout template by overidding the
    protected override string LayoutTemplateName;
     
    or
     
    public override string LayoutTemplatePath;

    There are a couple other virtual functions of the Registration Form that you can override to insert you custom logic. After you have completed you custom logic, then you can call the base method and all will work like the default implementation.

    Hope this helps,
    Bobby





  3. mstoffel
    mstoffel avatar
    27 posts
    Registered:
    13 Jul 2005
    03 Apr 2012
    Link to this post
    Thanks Bobby for your response.
    Can you give me a basic example how you inherit from the RegistrationForm? 

    Ok finally I found it about how you inherit RegistrationForm

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Sitefinity.Web.UI;
    using Telerik.Sitefinity.Security.Web.UI;
     
     
    namespace SitefinityWebApp.UserControls
    {
        public class customRegistrationForm : RegistrationForm
        {
     
            protected override void RegisterButton_Click(object sender, System.EventArgs e)
            {
                // Hello Registration
                
            }
        }
    }

    Now my question is what do you mean you call the base method?

    ok I answer to myself:

    base.RegisterButton_Click(sender, e);
  4. Bobby
    Bobby avatar
    8 posts
    Registered:
    04 Feb 2012
    09 Apr 2012
    Link to this post
    Hi Michel,

    I just created a new User registration form that contained extra information than what is provided out of the box. Here is the code that I used. I am not sure if you need this functionality but you can use this as an example of what you can do. To add the extra information for sitefinity to persist, I went to the admin part of the site and went to

    1. Administration -> Users.
    2. Once on the users page, look to the far right and you will see a section called 'Settings For Users'. Under this section, click on the link that says Manage Profile Types.
    3. When the Manage Profile Types UI is launched, you will see 'Basic Profile'. Click the link to edit this profile. This is the UI where you can add extra fields to a user.
    4. Once I added those fields I created my custom template to display the new UI and the custom class to save and validate my custom information.
    5. The Sitefinity Registration control will save any FieldControls located in the UI as long as each FieldControl that needs saving contains a DataFieldName and DataItemType as shown in my template. If a FieldControl does not contain these two properties, it will be ignored.

    Below is my code and my template for the UI.


    <%@ Control Language="C#" %>
     
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Fields" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sfvalidation" Namespace="Telerik.Sitefinity.Web.UI.Validation.Definitions" Assembly="Telerik.Sitefinity"%>
    <%@ Register TagPrefix="pintek" Namespace="Controls" Assembly="Controls" %>
     
    <fieldset class="sfregisterFormWrp">
        <asp:Panel ID="formContainer" runat="server" DefaultButton="registerButton">
            <ol class="sfregisterFieldsList">
                <sf:TextField ID="firstName" runat="server" DataFieldName="FirstName" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" DisplayMode="Write" Title="<%$ Resources:Labels, FirstName %>" CssClass="sfregisterField sfregisterFirstName" WrapperTag="li" />
                <sf:TextField ID="lastName" runat="server" DataFieldName="LastName" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" DisplayMode="Write" Title="<%$ Resources:Labels, LastName %>" CssClass="sfregisterField sfregisterLastName" WrapperTag="li" />
                <sf:TextField ID="email" runat="server" DataFieldName="Email" DisplayMode="Write" Title="<%$ Resources:Labels, Email %>" CssClass="sfregisterField sfregisterEmail" WrapperTag="li">
                    <ValidatorDefinition MessageCssClass="sfError" Required="true" ExpectedFormat="EmailAddress"/>
                </sf:TextField>
                <sf:TextField ID="userName" runat="server" DataFieldName="UserName" DisplayMode="Write" Title="<%$ Resources:Labels, UserName %>" CssClass="sfregisterField sfregisterUserName" WrapperTag="li">
                    <ValidatorDefinition MessageCssClass="sfError" Required="true"/>
                </sf:TextField>
                <sf:TextField ID="password" runat="server" DisplayMode="Write" Title="<%$ Resources:Labels, Password %>" IsPasswordMode="true" CssClass="sfregisterField sfregisterPassword" WrapperTag="li">
                    <ValidatorDefinition MessageCssClass="sfError" Required="true"/>
                </sf:TextField>
                <sf:TextField ID="reTypePassword" runat="server" DisplayMode="Write" Title="<%$ Resources:UserProfilesResources, ReTypePassword %>" IsPasswordMode="true" CssClass="sfregisterField sfregisterConfirmPassword" WrapperTag="li">
                    <ValidatorDefinition MessageCssClass="sfError">
                        <ComparingValidatorDefinitions>
                            <sfvalidation:ComparingValidatorDefinition ControlToCompare="password"
                                Operator="Equal" ValidationViolationMessage="<%$ Resources:ErrorMessages, CreateUserWizardDefaultConfirmPasswordCompareErrorMessage %>"/>
                        </ComparingValidatorDefinitions>
                    </ValidatorDefinition>
                </sf:TextField>
     
                <sf:ChoiceField ID="gender" runat="server" DisplayMode="Write" DataFieldName="gender" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" RenderChoicesAs="DropDown" Title="Gender*" MutuallyExclusive="false" WrapperTag="li">
                    <Choices>
                        <sitefinity:ChoiceItem text="Male" value="Male" />
                        <sitefinity:ChoiceItem text="Female" value="Female" />
                    </Choices>
                    <ValidatorDefinition MessageCssClass="sfError" Required="true"/>
                </sf:ChoiceField>
     
                <sf:TextField ID="zipcode" runat="server" DataFieldName="zip_code" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" DisplayMode="Write" Title="Zip Code" CssClass="sfregisterField sfregisterZipCode" WrapperTag="li">
                    <ValidatorDefinition MessageCssClass="sfError" Required="true" ExpectedFormat="USZipCode"/>
                </sf:TextField>
                 
                <!-- Right now, the site only supports regions in the U.S., hide this control -->
                <div style="display:none">
                    <pintek:CountryField ID="country" runat="server" DataFieldName="country" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" DisplayMode="Write" RenderChoicesAs="DropDown" MutuallyExclusive="true" Title="State" WrapperTag="li">
                        <ValidatorDefinition MessageCssClass="sfError" Required="true"/>
                    </pintek:CountryField>
                </div>
     
                <sf:DateField ID="birthday" DisplayMode="Write" Title="Birthday" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" DataFieldName="gender" Displaymode="Write" WrapperTag="Li" />
     
                <sf:ChoiceField ID="educationLevel" runat="server" DisplayMode="Write" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" DataFieldName="education_level" RenderChoicesAs="DropDown" Title="Highest Education Level" MutuallyExclusive="false" WrapperTag="li">
                    <Choices>
                        <sitefinity:ChoiceItem text="Leave Undislosed" value="Leave Undislosed" />
                        <sitefinity:ChoiceItem text="High School" value="High School" />
                        <sitefinity:ChoiceItem text="G.E.D" value="G.E.D" />
                        <sitefinity:ChoiceItem text="Bachelors" value="Bachelors" />
                        <sitefinity:ChoiceItem text="Masters" value="Masters" />
                        <sitefinity:ChoiceItem text="Phd" value="Phd" />
                    </Choices>
                    <ValidatorDefinition MessageCssClass="sfError" Required="true"/>
                </sf:ChoiceField>
     
                <sf:ChoiceField ID="incomeLevel" runat="server" DataFieldName="income_level" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" DisplayMode="Write" RenderChoicesAs="DropDown" Title="Income Level:" MutuallyExclusive="false" WrapperTag="li">
                    <Choices>
                        <sitefinity:ChoiceItem text="Leave Undislosed" value="Leave Undislosed" />
                        <sitefinity:ChoiceItem text="$10,000 - $50,000" value="$10,000 - $50,000" />
                        <sitefinity:ChoiceItem text="$50,000 - $100,000" value="$50,000 - $100,000" />
                        <sitefinity:ChoiceItem text="Above $100,000" value="Above $100,000" />
                    </Choices>
                    <ValidatorDefinition MessageCssClass="sfError" Required="true"/>
                </sf:ChoiceField>
     
                <sf:HierarchicalTaxonField ID="taxonomy" runat="server" Title="Categories of Interest" AutoPostBack="false" DataFieldName="business_services" DataItemType="Telerik.Sitefinity.Security.Model.SitefinityProfile" AllowMultipleSelection="true" AllowRootSelection="false" DisplayMode="Write" ShowCreateNewTaxonButton="false" ShowDoneSelectingButton="false" WrapperTag="Li" />
            </ol>
            <asp:Panel ID="errorsPanel" runat="server" CssClass="sfErrorSummary" Visible="false"/>
            <div class="sfregisterLnkWrp">
                <asp:Button runat="server" ID="registerButton" Text="<%$ Resources:UserProfilesResources, Register %>" CssClass="sfregisterSaveLnk"/>
            </div>
        </asp:Panel>
        <sf:SitefinityLabel id="successMessageLabel" runat="server" WrapperTagName="div" CssClass="sfSuccess" />
        <asp:Panel ID="configurationErrorsPanel" runat="server" CssClass="sfErrorSummary" Visible="false" >
            <div runat="server" id="smtpSettingsErrorWrapper" Visible="false">
                <asp:Label runat="server" id="smtpConfigurationErrorTitle" Text="<%$ Resources:ErrorMessages, CannotSendEmails %>"/>
                <asp:Label runat="server" id="smtpConfigurationError"></asp:Label>
            </div>
        </asp:Panel>
     
    </fieldset>

    Notice the DataItemType and DataFieldName for each field that I am saving. Here was the code that I used.

    using System;
    using System.Linq;
    using Telerik.Sitefinity.Security.Web.UI;
    using Telerik.Sitefinity.Taxonomies;
    using Telerik.Sitefinity.Taxonomies.Model;
    using Telerik.Sitefinity.Web.UI.Fields;
     
     
    namespace PublicControls
    {
        public class UserRegistration : RegistrationForm
        {
            private const string TemplateName = "PublicControls.Resources.Views.UserRegistration.ascx";
            
            protected override string LayoutTemplateName
            {
                get
                {
                    return TemplateName;
                }
            }
     
            public override string LayoutTemplatePath
            {
                get
                {
                    return string.Empty;
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
     
            protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
            {
                base.InitializeControls(container);
     
                TaxonomyManager manager = TaxonomyManager.GetManager();
                var taxonomy = manager.GetTaxonomies<HierarchicalTaxonomy>().Where(i => i.Name == "BusinessServices");
     
                if (taxonomy.Count() == 1)
                {
                    HierarchicalTaxonomy services = taxonomy.Single();
     
                    Tree.TaxonomyId = services.Id;
                    Tree.TaxonomyProvider = manager.Provider.Name;
                    Tree.BindOnServer = true;
                    Tree.DataFieldName = "business_service";
                    Tree.WebServiceUrl = "~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc";
                    Tree.DataBind();
                }
            }
     
            protected override bool ValidateInput()
            {
                bool valid = base.ValidateInput();
                if (valid)
                {//lets validate the rest of our custom fields.
                    if (!Tree.IsValid())
                        return false;
     
                    if (!Gender.IsValid())
                        return false;
                }
     
                return valid;
            }
     
            protected HierarchicalTaxonField Tree
            {
                get
                {
                    return this.Container.GetControl<HierarchicalTaxonField>("taxonomy", true);
                }
            }
     
            protected ChoiceField Gender
            {
                get
                {
                    return this.Container.GetControl<ChoiceField>("gender", true);
                }
            }
        }
    }

    If this answered your questions could you mark this reply as the answer.

    Hope this helps,
    Bobby
  5. doug
    doug avatar
    9 posts
    Registered:
    24 Jan 2011
    14 Feb 2013 in reply to Bobby
    Link to this post

    i am trying to do the same functionality (using my converted vb site).  i need to send email to admin for all reg.  the admin will approve/disapprove. 

    I created the class below, however it's not being called once i test the reg. form.  i added ~/lelcode/CustomRegistration.vb to the control section.  what am i doing wrong?  Please be basic i'm new to sf.   Version 5.1

    Imports System

    Imports System.Collections.Generic

    Imports System.Linq

    Imports System.Web

    Imports Telerik.Sitefinity.Web.UI

    Imports Telerik.Sitefinity.Security.Web.UI

    Namespace SitefinityWebApp.UserControls

    Public Class CustomRegistration
    Inherits RegistrationForm

    Protected Overrides Sub SendRegistrationConfirmationEmail(user As Telerik.Sitefinity.Security.Model.User, userManager As Telerik.Sitefinity.Security.UserManager)
    user.Email = "admin@mymail.com"
     MyBase.SendRegistrationConfirmationEmail(user, userManager)

    End Sub

    End Class
    End Namespace

  6. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    19 Feb 2013
    Link to this post
    Hello Doug,

    Thank you for using our services.

    Can you please let us knwo if when registering your custom control you've used a relative path or the CLR type of the control? Please note that in order to override the base RegistrationForm methods you need to create a custom control (class inheriting from RegistrationForm, not a Web UserControl whose code-behind inherits from RegistrationForm) and register it as per the instructions provided on this page from our documentation.


    Regards,
    Boyan Barnev
    the Telerik team
6 posts, 0 answered