Copied to clipboard

Flag this post as spam?

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


  • Devin 87 posts 251 karma points
    May 13, 2014 @ 15:14
    Devin
    0

    Update MemberType property based on dropdown list select value

    I have created a property under a MemberType called "testField" which is using a custom DataType dropdown list with 2 values in it (Employee and Subcontractor). I would like for a user to be able to select one, submit a form and to store their selection under this property, but I can't seem to figure it out.

    Is it possible to do this whilst being able to change their selection manually in the back end?

    Here's my code...

    ASCX

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Register.ascx.cs" Inherits="nForum.usercontrols.nForum.membership.Register" %>

       
    <div id="forumregistration" class="validate">
               
    <dl class="form">
                   
    <dt><label for="<%= tbLoginName.ClientID %>">Login/Username:</label></dt>
                   
    <dd><asp:TextBox ToolTip="Enter username" CssClass="required" ID="tbLoginName" runat="server" /></dd>

                   
    <dt><label for="<%= tbName.ClientID %>">Full Name:</label></dt>
                   
    <dd><asp:TextBox ToolTip="Enter name" CssClass="required" ID="tbName" runat="server" /></dd>

                   
    <dt><label for="<%= tbEmail.ClientID %>">Email:</label></dt>
                   
    <dd><asp:TextBox ToolTip="Enter email address" CssClass="required email" ID="tbEmail" runat="server" /></dd>

                   
    <dt><label for="<%= tbPassword.ClientID %>">Password:</label></dt>
                   
    <dd><asp:TextBox ToolTip="Enter a password" CssClass="required password" ID="tbPassword" TextMode="Password" runat="server" /></dd>

                   
    <dt><label for="">Organisation:</label></dt>
                   
    <asp:dropdownlist ID="tbOrganisation" runat="server">
                       
    <asp:ListItem Text="Choose" Value="0"></asp:ListItem>
                       
    <asp:ListItem Text="Employee" Value="1"></asp:ListItem>
                       
    <asp:ListItem Text="Subcontractor" Value="2"></asp:ListItem>
                   
    </asp:dropdownlist>
                   
    <dt> </dt>
                   
    <dd><asp:Button ID="btnSubmit" CssClass="textarea" runat="server" Text="Create Account" onclick="BtnSubmitClick" /></dd>

               
    </dl>
       
    </div>

    CS

    using System;
    using System.Text;
    using System.Web.Security;
    using nForum.BusinessLogic;
    using umbraco;
    using umbraco.cms.businesslogic.member;

    namespace nForum.usercontrols.nForum.membership
    {
       
    public partial class Register : BaseForumUsercontrol
       
    {

           
    protected void BtnSubmitClick(object sender, EventArgs e)
           
    {
               
    var redirecturl = Settings.Url;

               
    // Check the user isn't already registered
               
    if (Member.GetMemberFromEmail(Helpers.GetSafeHtml(tbEmail.Text)) == null & Member.GetMemberFromLoginName(Helpers.GetSafeHtml(tbLoginName.Text)) == null)
               
    {
                   
    // Set the member type and group
                   
    var mt = MemberType.GetByAlias(MembershipHelper.ForumUserRoleName);
                   
    var addToMemberGroup = MemberGroup.GetByName(MembershipHelper.ForumUserRoleName);

                   
    //create a member
                   
    var m = Member.MakeNew(Helpers.GetSafeHtml(tbName.Text), mt, new umbraco.BusinessLogic.User(0));

                   
    //var mstatus = new MembershipCreateStatus();
                   
    //var mp = Membership.CreateUser(tbName.Text, tbPassword.Text, tbEmail.Text, string.Empty, string.Empty, true, out mstatus);

                   
    // Set the other properties
                    m
    .Email = Helpers.GetSafeHtml(tbEmail.Text);
                    m
    .LoginName = Helpers.GetSafeHtml(tbLoginName.Text);
                    m
    .Password = Helpers.GetSafeHtml(tbPassword.Text);
                   
    // Add 0 Karma to user, helps us later in the site
                    m
    .getProperty("forumUserKarma").Value = 0;
                    m
    .getProperty("forumUserAllowPrivateMessages").Value = 1;
                    m
    .getProperty("forumUserLastPrivateMessage").Value = DateTime.Now;

                   
    // Take selected dropdown value and store
                    m
    .getProperty("testField").Value = tbOrganisation;

                   
    //##### Manual Member Authorisation #####
                   
    // If this is not enabled, mark the member as authorised
                   
    if (!Settings.ManuallyAuthoriseNewMembers)
                   
    {
                        m
    .getProperty("forumUserIsAuthorised").Value = 1;
                   
    }

                    m
    .AddGroup(addToMemberGroup.Id);

                   
    //Save member
                    m
    .Save();

                   
    //Generate member Xml Cache
                    m
    .XmlGenerate(new System.Xml.XmlDocument());

                   
    if (!Settings.ManuallyAuthoriseNewMembers)
                   
    {
                       
    //Login the user so they can be redirected to their profile page
                       
    FormsAuthentication.SetAuthCookie(tbLoginName.Text, false);
                   
    }
                   
    else
                   
    {
                        redirecturl
    = string.Concat(CurrentPageAbsoluteUrl, "?m=", library.GetDictionaryItem("NotifiedWhenAccountAuth"));
                   
    }

                   
    // If admins wants email notification, then send it here
                   
    if (Settings.EmailAdminOnNewMemberSignUp)
                   
    {
                       
    SendAdminNotification(m);
                   
    }
               
    }
               
    else
               
    {
                    redirecturl
    = string.Concat(CurrentPageAbsoluteUrl, "?m=", library.GetDictionaryItem("UserAlreadyExists"));
               
    }

               
    // Now redirect to the correct page
               
    Response.Redirect("/discuss-it");

           
    }

           
    private void SendAdminNotification(Member newmember)
           
    {
               
    var sb = new StringBuilder();
                sb
    .AppendFormat(library.GetDictionaryItem("MemberSignUpEmailText"),
                   
    Settings.Name,
                    newmember
    .LoginName,
                    newmember
    .Text,
                    newmember
    .Email);
               
    Helpers.SendMail(Settings.EmailNotification, Settings.EmailAdmin, library.GetDictionaryItem("NewMemberSignUp"), sb.ToString());
           
    }
       
    }
    }
  • Devin 87 posts 251 karma points
    May 13, 2014 @ 17:58
    Devin
    100

    Nevermind, fixed it myself :)

    I had to change

    m.getProperty("testField").Value= tbOrganisation;

    to


    m.getProperty("testField").Value = tbOrganisation.SelectedValue;

    And also the value IDs needed to match those in my DataType prevalues.

Please Sign in or register to post replies

Write your reply to:

Draft