protected void CreateUserWizard1CreatedUser(object sender, EventArgs e) { var newMember = Members.GetMember(CreateUserWizard1.UserName); XElement root = _memberFields.Root; var properties = RegHelper.GetProperties(newMember); var fields = root.Elements().Where(a => a.Attribute("Show").Value == "true" && a.Attribute("Group").Value == "Member"); foreach (XElement field in fields) { var prop = properties.SingleOrDefault(p => p.Name == field.Name); Registration attr = (Registration)prop.GetCustomAttributes(false)[0]; switch (attr.Control) { case "Text" : case "LongText": var tfinder = new ControlFinder<TextBox>(); tfinder.FindChildControlsRecursive(CreateUserWizard1.CreateUserStep.ContentTemplateContainer); var tinfo = tfinder.FoundControls.ToList(); if (tinfo.Any(t => t.ID == field.Name)) prop.SetValue(newMember, Convert.ChangeType(tinfo.Single(t => t.ID == field.Name).Text, prop.PropertyType), null); break; case "DatePicker" : var dfinder = new ControlFinder<DobPicker>(); dfinder.FindChildControlsRecursive(CreateUserWizard1.CreateUserStep.ContentTemplateContainer); var dinfo = dfinder.FoundControls.ToList(); if (dinfo.Any(t => t.ID == field.Name)) { newMember.DateOfBirth = dinfo.Single(t => t.ID == field.Name).DOBStr; newMember.Age = Common.GetAgeFromDOB(newMember.DateOfBirth); } break; case "GenderLookup" : var cfinder = new ControlFinder<GenderDropDownList>(); cfinder.FindChildControlsRecursive(CreateUserWizard1.CreateUserStep.ContentTemplateContainer); var cinfo = cfinder.FoundControls.ToList(); if (cinfo.Any(t => t.ID == field.Name)) newMember.Gender = cinfo.Single(t => t.ID == field.Name).SelectedValue; break; } } newMember.MembersIP = Common.GetIP4Address(); newMember.LastIP = newMember.MembersIP; // Save the profile - must be done since we explicitly created this profile instance Members.SaveMember(newMember); Membership.GetUser(newMember.Username,true); }
private Panel LoadGroupControls(string groupname) { var properties = RegHelper.GetProperties(new MemberInfo()); Panel grpPanel = null; _memberFields = XDocument.Load(_regsettings); XElement root = _memberFields.Root; //get all the controls to be shown and order by groupname so we can arrange on the wizard grpPanel = new Panel { ID = "pnl" + groupname, GroupingText = RegHelper.SplitCamelCase(groupname) }; foreach (XElement elem in root.Elements().Where(a => a.Attribute("Show").Value == "true" && a.Attribute("Group").Value == groupname)) { //get the custom attributes for the current property so we can get the control to use var prop = properties.SingleOrDefault(p => p.Name == elem.Name.LocalName); Registration attr = (Registration)prop.GetCustomAttributes(false)[0]; //var isVisible = Convert.ToBoolean(elem.Attribute("Show").Value); var isRequired = Convert.ToBoolean(elem.Attribute("Require").Value); RegControl ctl = new RegControl() { ValidationGroup = CreateUserWizard1.ID, LabelText = RegHelper.SplitCamelCase(elem.Name.LocalName), ControlID = elem.Name.LocalName, ControlType = attr.Control, InvalidMessage = isRequired ? elem.Name.LocalName + " Is required" : "", Show = true, Required = isRequired, ClientScript = "true", CssClass = isRequired ? "label_mandatory" : "label_not_mandatory" }; //add the new control to the panel grpPanel.Controls.Add(ctl); } return grpPanel; }
protected void SaveOptions(object sender, EventArgs e) { var newMember = Members.GetMember(CreateUserWizard1.UserName); XElement root = _memberFields.Root; var properties = RegHelper.GetProperties(newMember); var fields = root.Elements().Where(a => a.Attribute("Show").Value == "true" && a.Attribute("Group").Value != "Member"); foreach (XElement field in fields) { var prop = properties.SingleOrDefault(p => p.Name == field.Name); Registration attr = (Registration)prop.GetCustomAttributes(false)[0]; switch (attr.Control) { case "Text": case "LongText" : var tfinder = new ControlFinder<TextBox>(); tfinder.FindChildControlsRecursive(CreateUserWizard1.WizardSteps[2]); var tinfo = tfinder.FoundControls.ToList(); if (tinfo.Any(t => t.ID == field.Name)) prop.SetValue(newMember, Convert.ChangeType(tinfo.Single(t => t.ID == field.Name).Text, prop.PropertyType), null); break; case "CheckBox" : var cfinder = new ControlFinder<CheckBox>(); cfinder.FindChildControlsRecursive(CreateUserWizard1.WizardSteps[2]); var cinfo = cfinder.FoundControls.ToList(); if (cinfo.Any(t => t.ID == field.Name)) prop.SetValue(newMember, Convert.ChangeType(cinfo.Single(t => t.ID == field.Name).Checked, prop.PropertyType), null); break; case "CountryLookup" : var dfinder = new ControlFinder<CountryDropDownList>(); dfinder.FindChildControlsRecursive(CreateUserWizard1.WizardSteps[2]); var dinfo = dfinder.FoundControls.ToList(); if (dinfo.Any(t => t.ID == field.Name)) prop.SetValue(newMember, Convert.ChangeType(dinfo.Single(t => t.ID == field.Name).SelectedValue, prop.PropertyType), null); break; case "TimeZoneLookup" : var tzfinder = new ControlFinder<TimeZoneListBox>(); tzfinder.FindChildControlsRecursive(CreateUserWizard1.WizardSteps[2]); var tzinfo = tzfinder.FoundControls.ToList(); if (tzinfo.Any(t => t.ID == field.Name)) { string tZone = tzinfo.Single(t => t.ID == field.Name).SelectedValue; prop.SetValue(newMember, Convert.ChangeType(tZone, prop.PropertyType), null); TimeZoneInfo tzoneInfo = TimeZoneInfo.FindSystemTimeZoneById(tZone); newMember.TimeOffset = tzoneInfo.BaseUtcOffset.TotalHours; } break; case "Lookup": var lfinder = new ControlFinder<DropDownList>(); lfinder.FindChildControlsRecursive(CreateUserWizard1.WizardSteps[2]); var linfo = lfinder.FoundControls.ToList(); if (linfo.Any(t => t.ID == field.Name)) prop.SetValue(newMember, Convert.ChangeType(linfo.Single(t => t.ID == field.Name).SelectedValue, prop.PropertyType), null); break; } } Members.SaveMember(newMember); }