2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
5 // Vladimir Krasnov <vladimirk@mainsoft.com>
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Web.Security;
33 using System.Collections;
34 using System.Collections.Specialized;
35 using System.ComponentModel;
37 using System.Net.Mail;
39 namespace System.Web.UI.WebControls
41 [BindableAttribute (false)]
42 public class CreateUserWizard : Wizard
44 public static readonly string ContinueButtonCommandName = "Continue";
45 private string _password = "";
46 private string _confirmPassword = "";
47 private MembershipProvider _provider = null;
48 private ITextControl _errorMessageLabel = null;
49 private MailDefinition _mailDefinition = null;
51 private Style _textBoxStyle = null;
52 private Style _validatorTextStyle = null;
54 private TableItemStyle _completeSuccessTextStyle = null;
55 private TableItemStyle _errorMessageStyle = null;
56 private TableItemStyle _hyperLinkStyle = null;
57 private TableItemStyle _instructionTextStyle = null;
58 private TableItemStyle _labelStyle = null;
59 private TableItemStyle _passwordHintStyle = null;
60 private TableItemStyle _titleTextStyle = null;
61 Style _createUserButtonStyle;
62 Style _continueButtonStyle;
64 private static readonly object CreatedUserEvent = new object ();
65 private static readonly object CreateUserErrorEvent = new object ();
66 private static readonly object CreatingUserEvent = new object ();
67 private static readonly object ContinueButtonClickEvent = new object ();
68 private static readonly object SendingMailEvent = new object ();
69 private static readonly object SendMailErrorEvent = new object ();
71 private CompleteWizardStep _completeWizardStep = null;
72 private CreateUserWizardStep _createUserWizardStep = null;
74 public CreateUserWizard ()
78 #region Public Properties
80 public override int ActiveStepIndex
82 get { return base.ActiveStepIndex; }
83 set { base.ActiveStepIndex = value; }
86 [LocalizableAttribute (true)]
87 [ThemeableAttribute (false)]
88 public virtual string Answer
92 object o = ViewState ["Answer"];
93 return (o == null) ? String.Empty : (string) o;
98 ViewState.Remove ("Answer");
100 ViewState ["Answer"] = value;
104 [LocalizableAttribute (true)]
105 public virtual string AnswerLabelText
109 object o = ViewState ["AnswerLabelText"];
110 return (o == null) ? Locale.GetText ("Security Answer:") : (string) o;
115 ViewState.Remove ("AnswerLabelText");
117 ViewState ["AnswerLabelText"] = value;
121 [LocalizableAttribute (true)]
122 public virtual string AnswerRequiredErrorMessage
126 object o = ViewState ["AnswerRequiredErrorMessage"];
127 return (o == null) ? Locale.GetText ("Security answer is required.") : (string) o;
132 ViewState.Remove ("AnswerRequiredErrorMessage");
134 ViewState ["AnswerRequiredErrorMessage"] = value;
138 [ThemeableAttribute (false)]
139 public virtual bool AutoGeneratePassword
143 object o = ViewState ["AutoGeneratePassword"];
144 return (o == null) ? false : (bool) o;
148 ViewState ["AutoGeneratePassword"] = value;
152 public CompleteWizardStep CompleteStep
156 if (_completeWizardStep == null) {
157 for (int i = 0; i < WizardSteps.Count; i++)
158 if (WizardSteps [i] is CompleteWizardStep) {
159 _completeWizardStep = (CompleteWizardStep) WizardSteps [i];
161 if (_completeWizardStep.Wizard == null)
162 _completeWizardStep.SetWizard (this);
165 return _completeWizardStep;
169 [LocalizableAttribute (true)]
170 public virtual string CompleteSuccessText
174 object o = ViewState ["CompleteSuccessText"];
175 return (o == null) ? Locale.GetText ("Your account has been successfully created.") : (string) o;
180 ViewState.Remove ("CompleteSuccessText");
182 ViewState ["CompleteSuccessText"] = value;
186 public TableItemStyle CompleteSuccessTextStyle
190 if (_completeSuccessTextStyle == null) {
191 _completeSuccessTextStyle = new TableItemStyle ();
192 if (IsTrackingViewState)
193 ((IStateManager) _completeSuccessTextStyle).TrackViewState ();
195 return _completeSuccessTextStyle;
199 public virtual string ConfirmPassword
201 get { return _confirmPassword; }
204 [LocalizableAttribute (true)]
205 public virtual string ConfirmPasswordCompareErrorMessage
209 object o = ViewState ["ConfirmPasswordCompareErrorMessage"];
210 return (o == null) ? Locale.GetText ("The Password and Confirmation Password must match.") : (string) o;
215 ViewState.Remove ("ConfirmPasswordCompareErrorMessage");
217 ViewState ["ConfirmPasswordCompareErrorMessage"] = value;
221 [LocalizableAttribute (true)]
222 public virtual string ConfirmPasswordLabelText
226 object o = ViewState ["ConfirmPasswordLabelText"];
227 return (o == null) ? Locale.GetText ("Confirm Password:") : (string) o;
232 ViewState.Remove ("ConfirmPasswordLabelText");
234 ViewState ["ConfirmPasswordLabelText"] = value;
238 [LocalizableAttribute (true)]
239 public virtual string ConfirmPasswordRequiredErrorMessage
243 object o = ViewState ["ConfirmPasswordRequiredErrorMessage"];
244 return (o == null) ? Locale.GetText ("Confirm Password is required.") : (string) o;
249 ViewState.Remove ("ConfirmPasswordRequiredErrorMessage");
251 ViewState ["ConfirmPasswordRequiredErrorMessage"] = value;
255 public virtual string ContinueButtonImageUrl
257 get { return ViewState.GetString ("ContinueButtonImageUrl", String.Empty); }
258 set { ViewState ["ContinueButtonImageUrl"] = value; }
261 public Style ContinueButtonStyle
264 if (_continueButtonStyle == null) {
265 _continueButtonStyle = new Style ();
266 if (IsTrackingViewState)
267 ((IStateManager) _continueButtonStyle).TrackViewState ();
269 return _continueButtonStyle;
273 [LocalizableAttribute (true)]
274 public virtual string ContinueButtonText
276 get { return ViewState.GetString ("ContinueButtonText", "Continue"); }
277 set { ViewState ["ContinueButtonText"] = value; }
280 public virtual ButtonType ContinueButtonType
283 object v = ViewState ["ContinueButtonType"];
284 return v != null ? (ButtonType) v : ButtonType.Button;
287 ViewState ["ContinueButtonType"] = value;
291 [ThemeableAttribute (false)]
292 public virtual string ContinueDestinationPageUrl
296 object o = ViewState ["ContinueDestinationPageUrl"];
297 return (o == null) ? "" : (string) o;
302 ViewState.Remove ("ContinueDestinationPageUrl");
304 ViewState ["ContinueDestinationPageUrl"] = value;
308 public virtual string CreateUserButtonImageUrl
310 get { return ViewState.GetString ("CreateUserButtonImageUrl", String.Empty); }
311 set { ViewState ["CreateUserButtonImageUrl"] = value; }
314 public Style CreateUserButtonStyle
317 if (_createUserButtonStyle == null) {
318 _createUserButtonStyle = new Style ();
319 if (IsTrackingViewState)
320 ((IStateManager) _createUserButtonStyle).TrackViewState ();
322 return _createUserButtonStyle;
326 [LocalizableAttribute (true)]
327 public virtual string CreateUserButtonText
329 get { return ViewState.GetString ("CreateUserButtonText", "Create User"); }
330 set { ViewState ["CreateUserButtonText"] = value; }
333 public virtual ButtonType CreateUserButtonType
336 object v = ViewState ["CreateUserButtonType"];
337 return v != null ? (ButtonType) v : ButtonType.Button;
340 ViewState ["CreateUserButtonType"] = value;
344 public CreateUserWizardStep CreateUserStep
348 if (_createUserWizardStep == null) {
349 for (int i = 0; i < WizardSteps.Count; i++)
350 if (WizardSteps [i] is CreateUserWizardStep) {
351 _createUserWizardStep = (CreateUserWizardStep) WizardSteps [i];
353 if (_createUserWizardStep.Wizard == null)
354 _createUserWizardStep.SetWizard (this);
357 return _createUserWizardStep;
361 [ThemeableAttribute (false)]
362 public virtual bool DisableCreatedUser
366 object o = ViewState ["DisableCreatedUser"];
367 return (o == null) ? false : (bool) o;
371 ViewState ["DisableCreatedUser"] = value;
375 public override bool DisplaySideBar
378 return ViewState.GetBool ("DisplaySideBar", false);
381 ViewState ["DisplaySideBar"] = value;
382 ChildControlsCreated = false;
386 [LocalizableAttribute (true)]
387 public virtual string DuplicateEmailErrorMessage
391 object o = ViewState ["DuplicateEmailErrorMessage"];
392 return (o == null) ? Locale.GetText ("The e-mail address that you entered is already in use. Please enter a different e-mail address.") : (string) o;
397 ViewState.Remove ("DuplicateEmailErrorMessage");
399 ViewState ["DuplicateEmailErrorMessage"] = value;
403 [LocalizableAttribute (true)]
404 public virtual string DuplicateUserNameErrorMessage
408 object o = ViewState ["DuplicateUserNameErrorMessage"];
409 return (o == null) ? Locale.GetText ("Please enter a different user name.") : (string) o;
414 ViewState.Remove ("DuplicateUserNameErrorMessage");
416 ViewState ["DuplicateUserNameErrorMessage"] = value;
420 public virtual string EditProfileIconUrl
424 object o = ViewState ["EditProfileIconUrl"];
425 return (o == null) ? "" : (string) o;
430 ViewState.Remove ("EditProfileIconUrl");
432 ViewState ["EditProfileIconUrl"] = value;
436 [LocalizableAttribute (true)]
437 public virtual string EditProfileText
441 object o = ViewState ["EditProfileText"];
442 return (o == null) ? "" : (string) o;
447 ViewState.Remove ("EditProfileText");
449 ViewState ["EditProfileText"] = value;
453 public virtual string EditProfileUrl
457 object o = ViewState ["EditProfileUrl"];
458 return (o == null) ? "" : (string) o;
463 ViewState.Remove ("EditProfileUrl");
465 ViewState ["EditProfileUrl"] = value;
469 public virtual string Email
473 object o = ViewState ["Email"];
474 return (o == null) ? String.Empty : (string) o;
479 ViewState.Remove ("Email");
481 ViewState ["Email"] = value;
485 [LocalizableAttribute (true)]
486 public virtual string EmailLabelText
490 object o = ViewState ["EmailLabelText"];
491 return (o == null) ? Locale.GetText ("E-mail:") : (string) o;
496 ViewState.Remove ("EmailLabelText");
498 ViewState ["EmailLabelText"] = value;
502 public virtual string EmailRegularExpression
506 object o = ViewState ["EmailRegularExpression"];
507 return (o == null) ? "" : (string) o;
512 ViewState.Remove ("EmailRegularExpression");
514 ViewState ["EmailRegularExpression"] = value;
518 public virtual string EmailRegularExpressionErrorMessage
522 object o = ViewState ["EmailRegularExpressionErrorMessage"];
523 return (o == null) ? Locale.GetText ("Please enter a different e-mail.") : (string) o;
528 ViewState.Remove ("EmailRegularExpressionErrorMessage");
530 ViewState ["EmailRegularExpressionErrorMessage"] = value;
534 [LocalizableAttribute (true)]
535 public virtual string EmailRequiredErrorMessage
539 object o = ViewState ["EmailRequiredErrorMessage"];
540 return (o == null) ? Locale.GetText ("E-mail is required.") : (string) o;
545 ViewState.Remove ("EmailRequiredErrorMessage");
547 ViewState ["EmailRequiredErrorMessage"] = value;
551 public TableItemStyle ErrorMessageStyle
555 if (_errorMessageStyle == null) {
556 _errorMessageStyle = new TableItemStyle ();
557 if (IsTrackingViewState)
558 ((IStateManager) _errorMessageStyle).TrackViewState ();
560 return _errorMessageStyle;
564 public virtual string HelpPageIconUrl
568 object o = ViewState ["HelpPageIconUrl"];
569 return (o == null) ? "" : (string) o;
574 ViewState.Remove ("HelpPageIconUrl");
576 ViewState ["HelpPageIconUrl"] = value;
580 [LocalizableAttribute (true)]
581 public virtual string HelpPageText
585 object o = ViewState ["HelpPageText"];
586 return (o == null) ? "" : (string) o;
591 ViewState.Remove ("HelpPageText");
593 ViewState ["HelpPageText"] = value;
597 public virtual string HelpPageUrl
601 object o = ViewState ["HelpPageUrl"];
602 return (o == null) ? "" : (string) o;
607 ViewState.Remove ("HelpPageUrl");
609 ViewState ["HelpPageUrl"] = value;
613 public TableItemStyle HyperLinkStyle
617 if (_hyperLinkStyle == null) {
618 _hyperLinkStyle = new TableItemStyle ();
619 if (IsTrackingViewState)
620 ((IStateManager) _hyperLinkStyle).TrackViewState ();
622 return _hyperLinkStyle;
626 [LocalizableAttribute (true)]
627 public virtual string InstructionText
631 object o = ViewState ["InstructionText"];
632 return (o == null) ? "" : (string) o;
637 ViewState.Remove ("InstructionText");
639 ViewState ["InstructionText"] = value;
643 public TableItemStyle InstructionTextStyle
647 if (_instructionTextStyle == null) {
648 _instructionTextStyle = new TableItemStyle ();
649 if (IsTrackingViewState)
650 ((IStateManager) _instructionTextStyle).TrackViewState ();
652 return _instructionTextStyle;
656 [LocalizableAttribute (true)]
657 public virtual string InvalidAnswerErrorMessage
661 object o = ViewState ["InvalidAnswerErrorMessage"];
662 return (o == null) ? Locale.GetText ("Please enter a different security answer.") : (string) o;
667 ViewState.Remove ("InvalidAnswerErrorMessage");
669 ViewState ["InvalidAnswerErrorMessage"] = value;
673 [LocalizableAttribute (true)]
674 public virtual string InvalidEmailErrorMessage
678 object o = ViewState ["InvalidEmailErrorMessage"];
679 return (o == null) ? Locale.GetText ("Please enter a valid e-mail address.") : (string) o;
684 ViewState.Remove ("InvalidEmailErrorMessage");
686 ViewState ["InvalidEmailErrorMessage"] = value;
690 [MonoTODO ("take the values from membership provider")]
691 [LocalizableAttribute (true)]
692 public virtual string InvalidPasswordErrorMessage
696 object o = ViewState ["InvalidPasswordErrorMessage"];
697 return (o == null) ? Locale.GetText ("Password length minimum: {0}. Non-alphanumeric characters required: {1}.") : (string) o;
702 ViewState.Remove ("InvalidPasswordErrorMessage");
704 ViewState ["InvalidPasswordErrorMessage"] = value;
708 [LocalizableAttribute (true)]
709 public virtual string InvalidQuestionErrorMessage
713 object o = ViewState ["InvalidQuestionErrorMessage"];
714 return (o == null) ? Locale.GetText ("Please enter a different security question.") : (string) o;
719 ViewState.Remove ("InvalidQuestionErrorMessage");
721 ViewState ["InvalidQuestionErrorMessage"] = value;
725 public TableItemStyle LabelStyle
729 if (_labelStyle == null) {
730 _labelStyle = new TableItemStyle ();
731 if (IsTrackingViewState)
732 ((IStateManager) _labelStyle).TrackViewState ();
738 [ThemeableAttribute (false)]
739 public virtual bool LoginCreatedUser
743 object o = ViewState ["LoginCreatedUser"];
744 return (o == null) ? true : (bool) o;
748 ViewState ["LoginCreatedUser"] = value;
752 [ThemeableAttribute (false)]
753 public MailDefinition MailDefinition {
755 if (this._mailDefinition == null) {
756 this._mailDefinition = new MailDefinition();
757 if (IsTrackingViewState)
758 ((IStateManager) _mailDefinition).TrackViewState ();
760 return _mailDefinition;
764 [ThemeableAttribute (false)]
765 public virtual string MembershipProvider
769 object o = ViewState ["MembershipProvider"];
770 return (o == null) ? "" : (string) o;
775 ViewState.Remove ("MembershipProvider");
777 ViewState ["MembershipProvider"] = value;
783 internal virtual MembershipProvider MembershipProviderInternal
787 if (_provider == null)
788 InitMemberShipProvider ();
794 public virtual string Password
796 get { return _password; }
799 public TableItemStyle PasswordHintStyle
803 if (_passwordHintStyle == null) {
804 _passwordHintStyle = new TableItemStyle ();
805 if (IsTrackingViewState)
806 ((IStateManager) _passwordHintStyle).TrackViewState ();
808 return _passwordHintStyle;
812 [LocalizableAttribute (true)]
813 public virtual string PasswordHintText
817 object o = ViewState ["PasswordHintText"];
818 return (o == null) ? "" : (string) o;
823 ViewState.Remove ("PasswordHintText");
825 ViewState ["PasswordHintText"] = value;
829 [LocalizableAttribute (true)]
830 public virtual string PasswordLabelText
834 object o = ViewState ["PasswordLabelText"];
835 return (o == null) ? Locale.GetText ("Password:") : (string) o;
840 ViewState.Remove ("PasswordLabelText");
842 ViewState ["PasswordLabelText"] = value;
846 public virtual string PasswordRegularExpression
850 object o = ViewState ["PasswordRegularExpression"];
851 return (o == null) ? "" : (string) o;
856 ViewState.Remove ("PasswordRegularExpression");
858 ViewState ["PasswordRegularExpression"] = value;
862 public virtual string PasswordRegularExpressionErrorMessage
866 object o = ViewState ["PasswordRegularExpressionErrorMessage"];
867 return (o == null) ? Locale.GetText ("Please enter a different password.") : (string) o;
872 ViewState.Remove ("PasswordRegularExpressionErrorMessage");
874 ViewState ["PasswordRegularExpressionErrorMessage"] = value;
878 [LocalizableAttribute (true)]
879 public virtual string PasswordRequiredErrorMessage
883 object o = ViewState ["PasswordRequiredErrorMessage"];
884 return (o == null) ? Locale.GetText ("Password is required.") : (string) o;
889 ViewState.Remove ("PasswordRequiredErrorMessage");
891 ViewState ["PasswordRequiredErrorMessage"] = value;
895 [LocalizableAttribute (true)]
896 [ThemeableAttribute (false)]
897 public virtual string Question
901 object o = ViewState ["Question"];
902 return (o == null) ? String.Empty : (string) o;
907 ViewState.Remove ("Question");
909 ViewState ["Question"] = value;
913 [LocalizableAttribute (true)]
914 public virtual string QuestionLabelText
918 object o = ViewState ["QuestionLabelText"];
919 return (o == null) ? Locale.GetText ("Security Question:") : (string) o;
924 ViewState.Remove ("QuestionLabelText");
926 ViewState ["QuestionLabelText"] = value;
930 [LocalizableAttribute (true)]
931 public virtual string QuestionRequiredErrorMessage
935 object o = ViewState ["QuestionRequiredErrorMessage"];
936 return (o == null) ? Locale.GetText ("Security question is required.") : (string) o;
941 ViewState.Remove ("QuestionRequiredErrorMessage");
943 ViewState ["QuestionRequiredErrorMessage"] = value;
947 [ThemeableAttribute (false)]
948 public virtual bool RequireEmail
952 object o = ViewState ["RequireEmail"];
953 return (o == null) ? true : (bool) o;
957 ViewState ["RequireEmail"] = value;
961 [MonoTODO ("doesnt work")]
962 public override string SkipLinkText
966 object o = ViewState ["SkipLinkText"];
967 return (o == null) ? "" : (string) o;
972 ViewState.Remove ("SkipLinkText");
974 ViewState ["SkipLinkText"] = value;
978 public Style TextBoxStyle
982 if (_textBoxStyle == null) {
983 _textBoxStyle = new Style ();
984 if (IsTrackingViewState)
985 ((IStateManager) _textBoxStyle).TrackViewState ();
987 return _textBoxStyle;
991 public TableItemStyle TitleTextStyle
995 if (_titleTextStyle == null) {
996 _titleTextStyle = new TableItemStyle ();
997 if (IsTrackingViewState)
998 ((IStateManager) _titleTextStyle).TrackViewState ();
1000 return _titleTextStyle;
1004 [LocalizableAttribute (true)]
1005 public virtual string UnknownErrorMessage
1009 object o = ViewState ["UnknownErrorMessage"];
1010 return (o == null) ? Locale.GetText ("Your account was not created. Please try again.") : (string) o;
1015 ViewState.Remove ("UnknownErrorMessage");
1017 ViewState ["UnknownErrorMessage"] = value;
1021 public virtual string UserName
1025 object o = ViewState ["UserName"];
1026 return (o == null) ? String.Empty : (string) o;
1031 ViewState.Remove ("UserName");
1033 ViewState ["UserName"] = value;
1037 [LocalizableAttribute (true)]
1038 public virtual string UserNameLabelText
1042 object o = ViewState ["UserNameLabelText"];
1043 return (o == null) ? Locale.GetText ("User Name:") : (string) o;
1048 ViewState.Remove ("UserNameLabelText");
1050 ViewState ["UserNameLabelText"] = value;
1054 [LocalizableAttribute (true)]
1055 public virtual string UserNameRequiredErrorMessage
1059 object o = ViewState ["UserNameRequiredErrorMessage"];
1060 return (o == null) ? Locale.GetText ("User Name is required.") : (string) o;
1065 ViewState.Remove ("UserNameRequiredErrorMessage");
1067 ViewState ["UserNameRequiredErrorMessage"] = value;
1071 public Style ValidatorTextStyle
1075 if (_validatorTextStyle == null) {
1076 _validatorTextStyle = new Style ();
1077 if (IsTrackingViewState)
1078 ((IStateManager) _validatorTextStyle).TrackViewState ();
1080 return _validatorTextStyle;
1084 [ThemeableAttribute (false)]
1085 public override WizardStepCollection WizardSteps
1087 get { return base.WizardSteps; }
1092 #region Protected Properties
1094 protected internal bool QuestionAndAnswerRequired
1096 get { return MembershipProviderInternal.RequiresQuestionAndAnswer; }
1099 public event EventHandler ContinueButtonClick
1101 add { Events.AddHandler (ContinueButtonClickEvent, value); }
1102 remove { Events.RemoveHandler (ContinueButtonClickEvent, value); }
1105 public event EventHandler CreatedUser
1107 add { Events.AddHandler (CreatedUserEvent, value); }
1108 remove { Events.RemoveHandler (CreatedUserEvent, value); }
1111 public event CreateUserErrorEventHandler CreateUserError
1113 add { Events.AddHandler (CreateUserErrorEvent, value); }
1114 remove { Events.RemoveHandler (CreateUserErrorEvent, value); }
1117 public event LoginCancelEventHandler CreatingUser
1119 add { Events.AddHandler (CreatingUserEvent, value); }
1120 remove { Events.RemoveHandler (CreatingUserEvent, value); }
1123 public event MailMessageEventHandler SendingMail
1125 add { Events.AddHandler (SendingMailEvent, value); }
1126 remove { Events.RemoveHandler (SendingMailEvent, value); }
1129 public event SendMailErrorEventHandler SendMailError
1131 add { Events.AddHandler (SendMailErrorEvent, value); }
1132 remove { Events.RemoveHandler (SendMailErrorEvent, value); }
1138 #region Internal Properties
1140 internal override void InstantiateTemplateStep (TemplatedWizardStep step)
1142 if (step is CreateUserWizardStep) {
1143 InstantiateCreateUserWizardStep ((CreateUserWizardStep) step);
1145 else if (step is CompleteWizardStep) {
1146 InstantiateCompleteWizardStep ((CompleteWizardStep) step);
1149 base.InstantiateTemplateStep (step);
1153 private void InstantiateCompleteWizardStep (CompleteWizardStep step)
1155 CompleteStepContainer contentTemplateContainer = new CompleteStepContainer (this);
1156 if (step.ContentTemplate != null) {
1157 step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1160 new CompleteStepTemplate (this).InstantiateIn (contentTemplateContainer.InnerCell);
1161 contentTemplateContainer.ConfirmDefaultTemplate ();
1164 step.ContentTemplateContainer = contentTemplateContainer;
1165 step.Controls.Clear ();
1166 step.Controls.Add (contentTemplateContainer);
1168 BaseWizardNavigationContainer customNavigationTemplateContainer = new BaseWizardNavigationContainer ();
1169 if (step.CustomNavigationTemplate != null) {
1170 step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1171 RegisterCustomNavigation (step, customNavigationTemplateContainer);
1173 step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1176 void InstantiateCreateUserWizardStep (CreateUserWizardStep step)
1178 CreateUserStepContainer contentTemplateContainer = new CreateUserStepContainer (this);
1179 if (step.ContentTemplate != null) {
1180 step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1183 new CreateUserStepTemplate (this).InstantiateIn (contentTemplateContainer.InnerCell);
1184 contentTemplateContainer.ConfirmDefaultTemplate ();
1185 contentTemplateContainer.EnsureValidatorsState ();
1188 step.ContentTemplateContainer = contentTemplateContainer;
1189 step.Controls.Clear ();
1190 step.Controls.Add (contentTemplateContainer);
1192 CreateUserNavigationContainer customNavigationTemplateContainer = new CreateUserNavigationContainer (this);
1193 if (step.CustomNavigationTemplate != null) {
1194 step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1197 new CreateUserStepNavigationTemplate (this).InstantiateIn (customNavigationTemplateContainer);
1198 customNavigationTemplateContainer.ConfirmDefaultTemplate ();
1200 RegisterCustomNavigation (step, customNavigationTemplateContainer);
1202 step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1205 internal override ITemplate SideBarItemTemplate
1207 get { return new SideBarLabelTemplate (this); }
1212 #region Protected Methods
1214 protected internal override void CreateChildControls ()
1216 if (CreateUserStep == null)
1217 WizardSteps.AddAt (0, new CreateUserWizardStep ());
1219 if (CompleteStep == null)
1220 WizardSteps.AddAt (WizardSteps.Count, new CompleteWizardStep ());
1222 base.CreateChildControls ();
1225 protected override void CreateControlHierarchy ()
1227 base.CreateControlHierarchy ();
1229 CreateUserStepContainer container = CreateUserStep.ContentTemplateContainer as CreateUserStepContainer;
1231 if (container != null) {
1232 IEditableTextControl editable;
1233 editable = container.UserNameTextBox as IEditableTextControl;
1235 if (editable != null)
1236 editable.TextChanged += new EventHandler (UserName_TextChanged);
1238 if (!AutoGeneratePassword) {
1239 editable = container.PasswordTextBox as IEditableTextControl;
1241 if (editable != null)
1242 editable.TextChanged += new EventHandler (Password_TextChanged);
1244 editable = container.ConfirmPasswordTextBox as IEditableTextControl;
1246 if (editable != null)
1247 editable.TextChanged += new EventHandler (ConfirmPassword_TextChanged);
1251 editable = container.EmailTextBox as IEditableTextControl;
1253 if (editable != null)
1254 editable.TextChanged += new EventHandler (Email_TextChanged);
1257 if (QuestionAndAnswerRequired) {
1258 editable = container.QuestionTextBox as IEditableTextControl;
1260 if (editable != null)
1261 editable.TextChanged += new EventHandler (Question_TextChanged);
1263 editable = container.AnswerTextBox as IEditableTextControl;
1265 if (editable != null)
1266 editable.TextChanged += new EventHandler (Answer_TextChanged);
1269 _errorMessageLabel = container.ErrorMessageLabel;
1273 [MonoTODO ("Not Implemented")]
1274 protected override IDictionary GetDesignModeState ()
1276 throw new NotImplementedException ();
1279 protected override bool OnBubbleEvent (object source, EventArgs e)
1281 CommandEventArgs args = e as CommandEventArgs;
1282 if (e != null && args.CommandName == ContinueButtonCommandName) {
1283 ProcessContinueEvent ();
1286 return base.OnBubbleEvent (source, e);
1289 private void ProcessContinueEvent () {
1290 OnContinueButtonClick (EventArgs.Empty);
1292 if (ContinueDestinationPageUrl.Length > 0) {
1293 Context.Response.Redirect (ContinueDestinationPageUrl);
1297 protected virtual void OnContinueButtonClick (EventArgs e)
1299 if (Events != null) {
1300 EventHandler eh = (EventHandler) Events [ContinueButtonClickEvent];
1301 if (eh != null) eh (this, e);
1305 protected virtual void OnCreatedUser (EventArgs e)
1307 if (Events != null) {
1308 EventHandler eh = (EventHandler) Events [CreatedUserEvent];
1309 if (eh != null) eh (this, e);
1313 protected virtual void OnCreateUserError (CreateUserErrorEventArgs e)
1315 if (Events != null) {
1316 CreateUserErrorEventHandler eh = (CreateUserErrorEventHandler) Events [CreateUserErrorEvent];
1317 if (eh != null) eh (this, e);
1321 protected virtual void OnCreatingUser (LoginCancelEventArgs e)
1323 if (Events != null) {
1324 LoginCancelEventHandler eh = (LoginCancelEventHandler) Events [CreatingUserEvent];
1325 if (eh != null) eh (this, e);
1329 protected override void OnNextButtonClick (WizardNavigationEventArgs e)
1331 if (ActiveStep == CreateUserStep) {
1332 bool userCreated = CreateUser ();
1336 if (LoginCreatedUser)
1339 base.OnNextButtonClick (e);
1342 protected internal override void OnPreRender (EventArgs e)
1344 base.OnPreRender (e);
1347 protected virtual void OnSendingMail (MailMessageEventArgs e)
1349 if (Events != null) {
1350 MailMessageEventHandler eh = (MailMessageEventHandler) Events [SendingMailEvent];
1351 if (eh != null) eh (this, e);
1355 protected virtual void OnSendMailError (SendMailErrorEventArgs e)
1357 if (Events != null) {
1358 SendMailErrorEventHandler eh = (SendMailErrorEventHandler) Events [SendMailErrorEvent];
1359 if (eh != null) eh (this, e);
1363 protected override void LoadViewState (object savedState)
1365 if (savedState == null) {
1366 base.LoadViewState (null);
1370 object [] states = (object []) savedState;
1371 base.LoadViewState (states [0]);
1373 if (states [1] != null)
1374 ((IStateManager) TextBoxStyle).LoadViewState (states [1]);
1375 if (states [2] != null)
1376 ((IStateManager) ValidatorTextStyle).LoadViewState (states [2]);
1377 if (states [3] != null)
1378 ((IStateManager) CompleteSuccessTextStyle).LoadViewState (states [3]);
1379 if (states [4] != null)
1380 ((IStateManager) ErrorMessageStyle).LoadViewState (states [4]);
1381 if (states [5] != null)
1382 ((IStateManager) HyperLinkStyle).LoadViewState (states [5]);
1383 if (states [6] != null)
1384 ((IStateManager) InstructionTextStyle).LoadViewState (states [6]);
1385 if (states [7] != null)
1386 ((IStateManager) LabelStyle).LoadViewState (states [7]);
1387 if (states [8] != null)
1388 ((IStateManager) PasswordHintStyle).LoadViewState (states [8]);
1389 if (states [9] != null)
1390 ((IStateManager) TitleTextStyle).LoadViewState (states [9]);
1391 if (states [10] != null)
1392 ((IStateManager) CreateUserButtonStyle).LoadViewState (states [10]);
1393 if (states [11] != null)
1394 ((IStateManager) ContinueButtonStyle).LoadViewState (states [11]);
1395 if (states [12] != null)
1396 ((IStateManager) MailDefinition).LoadViewState (states [12]);
1398 ((CreateUserStepContainer) CreateUserStep.ContentTemplateContainer).EnsureValidatorsState ();
1401 protected override object SaveViewState ()
1403 object [] state = new object [13];
1404 state [0] = base.SaveViewState ();
1406 if (_textBoxStyle != null)
1407 state [1] = ((IStateManager) _textBoxStyle).SaveViewState ();
1408 if (_validatorTextStyle != null)
1409 state [2] = ((IStateManager) _validatorTextStyle).SaveViewState ();
1410 if (_completeSuccessTextStyle != null)
1411 state [3] = ((IStateManager) _completeSuccessTextStyle).SaveViewState ();
1412 if (_errorMessageStyle != null)
1413 state [4] = ((IStateManager) _errorMessageStyle).SaveViewState ();
1414 if (_hyperLinkStyle != null)
1415 state [5] = ((IStateManager) _hyperLinkStyle).SaveViewState ();
1416 if (_instructionTextStyle != null)
1417 state [6] = ((IStateManager) _instructionTextStyle).SaveViewState ();
1418 if (_labelStyle != null)
1419 state [7] = ((IStateManager) _labelStyle).SaveViewState ();
1420 if (_passwordHintStyle != null)
1421 state [8] = ((IStateManager) _passwordHintStyle).SaveViewState ();
1422 if (_titleTextStyle != null)
1423 state [9] = ((IStateManager) _titleTextStyle).SaveViewState ();
1424 if (_createUserButtonStyle != null)
1425 state [10] = ((IStateManager) _createUserButtonStyle).SaveViewState ();
1426 if (_continueButtonStyle != null)
1427 state [11] = ((IStateManager) _continueButtonStyle).SaveViewState ();
1428 if (_mailDefinition != null)
1429 state [12] = ((IStateManager) _mailDefinition).SaveViewState ();
1431 for (int n = 0; n < state.Length; n++)
1432 if (state [n] != null)
1438 [MonoTODO ("for design-time usage - no more details available")]
1439 protected override void SetDesignModeState (IDictionary data)
1441 base.SetDesignModeState (data);
1444 protected override void TrackViewState ()
1446 base.TrackViewState ();
1447 if (_textBoxStyle != null)
1448 ((IStateManager) _textBoxStyle).TrackViewState ();
1449 if (_validatorTextStyle != null)
1450 ((IStateManager) _validatorTextStyle).TrackViewState ();
1451 if (_completeSuccessTextStyle != null)
1452 ((IStateManager) _completeSuccessTextStyle).TrackViewState ();
1453 if (_errorMessageStyle != null)
1454 ((IStateManager) _errorMessageStyle).TrackViewState ();
1455 if (_hyperLinkStyle != null)
1456 ((IStateManager) _hyperLinkStyle).TrackViewState ();
1457 if (_instructionTextStyle != null)
1458 ((IStateManager) _instructionTextStyle).TrackViewState ();
1459 if (_labelStyle != null)
1460 ((IStateManager) _labelStyle).TrackViewState ();
1461 if (_passwordHintStyle != null)
1462 ((IStateManager) _passwordHintStyle).TrackViewState ();
1463 if (_titleTextStyle != null)
1464 ((IStateManager) _titleTextStyle).TrackViewState ();
1465 if (_createUserButtonStyle != null)
1466 ((IStateManager) _createUserButtonStyle).TrackViewState ();
1467 if (_continueButtonStyle != null)
1468 ((IStateManager) _continueButtonStyle).TrackViewState ();
1469 if (_mailDefinition != null)
1470 ((IStateManager) _mailDefinition).TrackViewState ();
1475 #region Private event handlers
1477 private void UserName_TextChanged (object sender, EventArgs e)
1479 UserName = ((ITextControl) sender).Text;
1482 private void Password_TextChanged (object sender, EventArgs e)
1484 _password = ((ITextControl) sender).Text;
1487 private void ConfirmPassword_TextChanged (object sender, EventArgs e)
1489 _confirmPassword = ((ITextControl) sender).Text;
1492 private void Email_TextChanged (object sender, EventArgs e)
1494 Email = ((ITextControl) sender).Text;
1497 private void Question_TextChanged (object sender, EventArgs e)
1499 Question = ((ITextControl) sender).Text;
1502 private void Answer_TextChanged (object sender, EventArgs e)
1504 Answer = ((ITextControl) sender).Text;
1509 #region Private Methods
1511 private void InitMemberShipProvider ()
1513 string mp = MembershipProvider;
1514 _provider = (mp.Length == 0) ? _provider = Membership.Provider : Membership.Providers [mp];
1515 if (_provider == null)
1516 throw new HttpException (Locale.GetText ("No provider named '{0}' could be found.", mp));
1519 private bool CreateUser ()
1524 if (AutoGeneratePassword)
1525 _password = GeneratePassword ();
1527 OnCreatingUser (new LoginCancelEventArgs (false));
1529 MembershipCreateStatus status;
1530 MembershipUser newUser = MembershipProviderInternal.CreateUser (
1531 UserName, Password, Email, Question, Answer, !DisableCreatedUser, null, out status);
1533 if ((newUser != null) && (status == MembershipCreateStatus.Success)) {
1534 OnCreatedUser (new EventArgs ());
\r
1535 SendPasswordByMail (newUser, Password);
1540 case MembershipCreateStatus.DuplicateUserName:
1541 ShowErrorMessage (DuplicateUserNameErrorMessage);
1544 case MembershipCreateStatus.InvalidPassword:
1545 ShowErrorMessage (String.Format (InvalidPasswordErrorMessage, MembershipProviderInternal.MinRequiredPasswordLength, MembershipProviderInternal.MinRequiredNonAlphanumericCharacters));
1548 case MembershipCreateStatus.DuplicateEmail:
1549 ShowErrorMessage (DuplicateEmailErrorMessage);
1552 case MembershipCreateStatus.InvalidEmail:
1553 ShowErrorMessage (InvalidEmailErrorMessage);
1556 case MembershipCreateStatus.InvalidQuestion:
1557 ShowErrorMessage (InvalidQuestionErrorMessage);
1560 case MembershipCreateStatus.InvalidAnswer:
1561 ShowErrorMessage (InvalidAnswerErrorMessage);
1564 case MembershipCreateStatus.UserRejected:
1565 case MembershipCreateStatus.InvalidUserName:
1566 case MembershipCreateStatus.ProviderError:
1567 case MembershipCreateStatus.InvalidProviderUserKey:
1568 ShowErrorMessage (UnknownErrorMessage);
1574 OnCreateUserError (new CreateUserErrorEventArgs (status));
1579 private void SendPasswordByMail (MembershipUser user, string password)
1584 if (_mailDefinition == null)
\r
1587 string messageText = "A new account has been created for you. Please go to the site and log in using the following information.\nUser Name: <%USERNAME%>\nPassword: <%PASSWORD%>";
1589 ListDictionary dictionary = new ListDictionary ();
\r
1590 dictionary.Add ("<%USERNAME%>", user.UserName);
\r
1591 dictionary.Add ("<%PASSWORD%>", password);
1593 MailMessage message = null;
1595 if (MailDefinition.BodyFileName.Length == 0)
1596 message = MailDefinition.CreateMailMessage (user.Email, dictionary, messageText, this);
1598 message = MailDefinition.CreateMailMessage (user.Email, dictionary, this);
1600 if (string.IsNullOrEmpty (message.Subject))
1601 message.Subject = "Account information";
1603 MailMessageEventArgs args = new MailMessageEventArgs (message);
1604 OnSendingMail (args);
1606 SmtpClient smtpClient = new SmtpClient ();
1608 smtpClient.Send (message);
1609 } catch (Exception e) {
1610 SendMailErrorEventArgs mailArgs = new SendMailErrorEventArgs (e);
1611 OnSendMailError (mailArgs);
1612 if (!mailArgs.Handled)
1617 private void Login ()
1619 bool userValidated = MembershipProviderInternal.ValidateUser (UserName, Password);
1621 FormsAuthentication.SetAuthCookie (UserName, false);
1624 private void ShowErrorMessage (string errorMessage)
1626 if (_errorMessageLabel != null)
1627 _errorMessageLabel.Text = errorMessage;
1630 private string GeneratePassword ()
1632 return Membership.GeneratePassword (8, 3);
1637 #region SideBarLabelTemplate
1639 class SideBarLabelTemplate : ITemplate
1643 public SideBarLabelTemplate (Wizard wizard)
1645 this.wizard = wizard;
1648 public void InstantiateIn (Control control)
1650 Label b = new Label ();
1651 wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1652 control.Controls.Add (b);
1653 control.DataBinding += Bound;
1656 void Bound (object s, EventArgs args)
1658 WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1660 Control c = (Control) s;
1661 Label b = (Label) c.Controls [0];
1662 b.ID = SideBarButtonID;
1663 b.Text = step.Title;
1670 sealed class CreateUserNavigationContainer : DefaultNavigationContainer
1672 CreateUserWizard _createUserWizard;
1674 public CreateUserNavigationContainer (CreateUserWizard createUserWizard)
1675 : base (createUserWizard)
1677 _createUserWizard = createUserWizard;
1680 protected override void UpdateState ()
1683 if (_createUserWizard.AllowNavigationToStep (_createUserWizard.ActiveStepIndex - 1)) {
1684 UpdateNavButtonState (Wizard.StepPreviousButtonID + Wizard.StepPreviousButtonType, Wizard.StepPreviousButtonText, Wizard.StepPreviousButtonImageUrl, Wizard.StepPreviousButtonStyle);
1687 ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1691 UpdateNavButtonState (Wizard.StepNextButtonID + _createUserWizard.CreateUserButtonType, _createUserWizard.CreateUserButtonText, _createUserWizard.CreateUserButtonImageUrl, _createUserWizard.CreateUserButtonStyle);
1694 if (Wizard.DisplayCancelButton) {
1695 UpdateNavButtonState (Wizard.CancelButtonID + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1698 ((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
1703 sealed class CreateUserStepNavigationTemplate : ITemplate
1705 readonly CreateUserWizard _createUserWizard;
1707 public CreateUserStepNavigationTemplate (CreateUserWizard createUserWizard) {
1708 _createUserWizard = createUserWizard;
1711 #region ITemplate Members
1713 public void InstantiateIn (Control container) {
1714 Table t = new Table ();
1717 t.Width = Unit.Percentage (100);
1718 t.Height = Unit.Percentage (100);
1719 TableRow row = new TableRow ();
\r
1721 AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.StepPreviousButtonID, Wizard.MovePreviousCommandName, false, _createUserWizard.ID));
\r
1722 AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.StepNextButtonID, Wizard.MoveNextCommandName, true, _createUserWizard.ID));
\r
1723 AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.CancelButtonID, Wizard.CancelCommandName, false, _createUserWizard.ID));
1726 container.Controls.Add (t);
1729 void AddButtonCell (TableRow row, params Control [] controls)
1731 TableCell cell = new TableCell ();
1732 cell.HorizontalAlign = HorizontalAlign.Right;
1733 for (int i = 0; i < controls.Length; i++)
1734 cell.Controls.Add (controls[i]);
1735 row.Cells.Add (cell);
1741 sealed class CreateUserStepContainer : DefaultContentContainer
1743 CreateUserWizard _createUserWizard;
1745 public CreateUserStepContainer (CreateUserWizard createUserWizard)
1746 : base (createUserWizard)
1748 _createUserWizard = createUserWizard;
1751 public Control UserNameTextBox {
1753 Control c = FindControl ("UserName");
1755 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID UserName for the username.");
1760 public Control PasswordTextBox {
1762 Control c = FindControl ("Password");
1764 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Password for the new password, this is required if AutoGeneratePassword = true.");
1769 public Control ConfirmPasswordTextBox {
1771 Control c = FindControl ("Password");
1775 public Control EmailTextBox {
1777 Control c = FindControl ("Email");
1779 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Email for the e-mail, this is required if RequireEmail = true.");
1784 public Control QuestionTextBox {
1786 Control c = FindControl ("Question");
1788 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Question for the security question, this is required if your membership provider requires a question and answer.");
1793 public Control AnswerTextBox {
1795 Control c = FindControl ("Answer");
1797 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Answer for the security answer, this is required if your membership provider requires a question and answer.");
1802 public ITextControl ErrorMessageLabel {
1803 get { return FindControl ("ErrorMessage") as ITextControl; }
1806 protected override void UpdateState () {
1808 if (String.IsNullOrEmpty (_createUserWizard.CreateUserStep.Title)) {
1809 ((Table) InnerCell.Controls [0]).Rows [0].Visible = false;
1812 ((Table) InnerCell.Controls [0]).Rows [0].Cells [0].Text = _createUserWizard.CreateUserStep.Title;
1815 // Row #1 - InstructionText
1816 if (String.IsNullOrEmpty (_createUserWizard.InstructionText)) {
1817 ((Table) InnerCell.Controls [0]).Rows [1].Visible = false;
1820 ((Table) InnerCell.Controls [0]).Rows [1].Cells [0].Text = _createUserWizard.InstructionText;
1824 Label UserNameLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [2].Cells [0].Controls [0];
1825 UserNameLabel.Text = _createUserWizard.UserNameLabelText;
1827 RequiredFieldValidator UserNameRequired = (RequiredFieldValidator) FindControl ("UserNameRequired");
1828 UserNameRequired.ErrorMessage = _createUserWizard.UserNameRequiredErrorMessage;
1829 UserNameRequired.ToolTip = _createUserWizard.UserNameRequiredErrorMessage;
1831 if (_createUserWizard.AutoGeneratePassword) {
1832 ((Table) InnerCell.Controls [0]).Rows [3].Visible = false;
1833 ((Table) InnerCell.Controls [0]).Rows [4].Visible = false;
1834 ((Table) InnerCell.Controls [0]).Rows [5].Visible = false;
1838 Label PasswordLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [0];
1839 PasswordLabel.Text = _createUserWizard.PasswordLabelText;
1841 RequiredFieldValidator PasswordRequired = (RequiredFieldValidator) FindControl ("PasswordRequired");
1842 PasswordRequired.ErrorMessage = _createUserWizard.PasswordRequiredErrorMessage;
1843 PasswordRequired.ToolTip = _createUserWizard.PasswordRequiredErrorMessage;
1846 if (String.IsNullOrEmpty (_createUserWizard.PasswordHintText)) {
1847 ((Table) InnerCell.Controls [0]).Rows [4].Visible = false;
1850 ((Table) InnerCell.Controls [0]).Rows [4].Cells [1].Text = _createUserWizard.PasswordHintText;
1854 Label ConfirmPasswordLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [5].Cells [0].Controls [0];
1855 ConfirmPasswordLabel.Text = _createUserWizard.ConfirmPasswordLabelText;
1857 RequiredFieldValidator ConfirmPasswordRequired = (RequiredFieldValidator) FindControl ("ConfirmPasswordRequired");
1858 ConfirmPasswordRequired.ErrorMessage = _createUserWizard.ConfirmPasswordRequiredErrorMessage;
1859 ConfirmPasswordRequired.ToolTip = _createUserWizard.ConfirmPasswordRequiredErrorMessage;
1863 if (_createUserWizard.RequireEmail) {
1864 Label EmailLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [6].Cells [0].Controls [0];
1865 EmailLabel.Text = _createUserWizard.EmailLabelText;
1867 RequiredFieldValidator EmailRequired = (RequiredFieldValidator) FindControl ("EmailRequired");
1868 EmailRequired.ErrorMessage = _createUserWizard.EmailRequiredErrorMessage;
1869 EmailRequired.ToolTip = _createUserWizard.EmailRequiredErrorMessage;
1872 ((Table) InnerCell.Controls [0]).Rows [6].Visible = false;
1875 if (_createUserWizard.QuestionAndAnswerRequired) {
1877 Label QuestionLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [7].Cells [0].Controls [0];
1878 QuestionLabel.Text = _createUserWizard.QuestionLabelText;
1880 RequiredFieldValidator QuestionRequired = (RequiredFieldValidator) FindControl ("QuestionRequired");
1881 QuestionRequired.ErrorMessage = _createUserWizard.QuestionRequiredErrorMessage;
1882 QuestionRequired.ToolTip = _createUserWizard.QuestionRequiredErrorMessage;
1885 Label AnswerLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [8].Cells [0].Controls [0];
1886 AnswerLabel.Text = _createUserWizard.AnswerLabelText;
1888 RequiredFieldValidator AnswerRequired = (RequiredFieldValidator) FindControl ("AnswerRequired");
1889 AnswerRequired.ErrorMessage = _createUserWizard.AnswerRequiredErrorMessage;
1890 AnswerRequired.ToolTip = _createUserWizard.AnswerRequiredErrorMessage;
1893 ((Table) InnerCell.Controls [0]).Rows [7].Visible = false;
1894 ((Table) InnerCell.Controls [0]).Rows [8].Visible = false;
1898 if (_createUserWizard.AutoGeneratePassword) {
1899 ((Table) InnerCell.Controls [0]).Rows [9].Visible = false;
1902 CompareValidator PasswordCompare = (CompareValidator) FindControl ("PasswordCompare");
1903 PasswordCompare.ErrorMessage = _createUserWizard.ConfirmPasswordCompareErrorMessage;
1907 if (_createUserWizard.AutoGeneratePassword || String.IsNullOrEmpty (_createUserWizard.PasswordRegularExpression)) {
1908 ((Table) InnerCell.Controls [0]).Rows [10].Visible = false;
1911 RegularExpressionValidator PasswordRegEx = (RegularExpressionValidator) FindControl ("PasswordRegEx");
1912 PasswordRegEx.ValidationExpression = _createUserWizard.PasswordRegularExpression;
1913 PasswordRegEx.ErrorMessage = _createUserWizard.PasswordRegularExpressionErrorMessage;
1917 if (!_createUserWizard.RequireEmail || String.IsNullOrEmpty (_createUserWizard.EmailRegularExpression)) {
1918 ((Table) InnerCell.Controls [0]).Rows [11].Visible = false;
1921 RegularExpressionValidator EmailRegEx = (RegularExpressionValidator) FindControl ("EmailRegEx");
1922 EmailRegEx.ErrorMessage = _createUserWizard.EmailRegularExpressionErrorMessage;
1923 EmailRegEx.ValidationExpression = _createUserWizard.EmailRegularExpression;
1927 if (String.IsNullOrEmpty (ErrorMessageLabel.Text)) {
1928 ((Table) InnerCell.Controls [0]).Rows [12].Visible = false;
1933 Image img = (Image) ((Table) InnerCell.Controls [0]).Rows [13].Cells [0].Controls [0];
1934 if (String.IsNullOrEmpty (_createUserWizard.HelpPageIconUrl)) {
1935 img.Visible = false;
1938 img.ImageUrl = _createUserWizard.HelpPageIconUrl;
1939 img.AlternateText = _createUserWizard.HelpPageText;
1943 HyperLink link = (HyperLink) ((Table) InnerCell.Controls [0]).Rows [13].Cells [0].Controls [1];
1944 if (String.IsNullOrEmpty (_createUserWizard.HelpPageText)) {
1945 link.Visible = false;
1948 link.Text = _createUserWizard.HelpPageText;
1949 link.NavigateUrl = _createUserWizard.HelpPageUrl;
1952 ((Table) InnerCell.Controls [0]).Rows [13].Visible = img.Visible || link.Visible;
1956 public void EnsureValidatorsState ()
1958 if (!IsDefaultTemplate)
1961 ((RequiredFieldValidator) FindControl ("PasswordRequired")).Enabled = !_createUserWizard.AutoGeneratePassword;
1962 ((RequiredFieldValidator) FindControl ("ConfirmPasswordRequired")).Enabled = !_createUserWizard.AutoGeneratePassword;
1963 ((CompareValidator) FindControl ("PasswordCompare")).Enabled = !_createUserWizard.AutoGeneratePassword;
1964 RegularExpressionValidator PasswordRegEx = (RegularExpressionValidator) FindControl ("PasswordRegEx");
1965 PasswordRegEx.Enabled = !_createUserWizard.AutoGeneratePassword && !String.IsNullOrEmpty (_createUserWizard.PasswordRegularExpression);
1966 PasswordRegEx.ValidationExpression = _createUserWizard.PasswordRegularExpression;
1968 ((RequiredFieldValidator) FindControl ("EmailRequired")).Enabled = _createUserWizard.RequireEmail;
1969 RegularExpressionValidator EmailRegEx = (RegularExpressionValidator) FindControl ("EmailRegEx");
1970 EmailRegEx.Enabled = _createUserWizard.RequireEmail && !String.IsNullOrEmpty (_createUserWizard.EmailRegularExpression);
1971 EmailRegEx.ValidationExpression = _createUserWizard.EmailRegularExpression;
1973 ((RequiredFieldValidator) FindControl ("QuestionRequired")).Enabled = _createUserWizard.QuestionAndAnswerRequired;
1974 ((RequiredFieldValidator) FindControl ("AnswerRequired")).Enabled = _createUserWizard.QuestionAndAnswerRequired;
1978 sealed class CreateUserStepTemplate : ITemplate
1980 readonly CreateUserWizard _createUserWizard;
1982 public CreateUserStepTemplate (CreateUserWizard createUserWizard)
1984 _createUserWizard = createUserWizard;
1987 #region ITemplate Members
1989 TableRow CreateRow (Control c0, Control c1, Control c2, Style s0, Style s1) {
1990 TableRow row = new TableRow ();
1991 TableCell cell0 = new TableCell ();
1992 TableCell cell1 = new TableCell ();
1995 cell0.Controls.Add (c0);
1996 row.Controls.Add (cell0);
1998 if ((c1 != null) && (c2 != null)) {
1999 cell1.Controls.Add (c1);
2000 cell1.Controls.Add (c2);
2001 cell0.HorizontalAlign = HorizontalAlign.Right;
2004 _createUserWizard.RegisterApplyStyle (cell0, s0);
2006 _createUserWizard.RegisterApplyStyle (cell1, s1);
2008 row.Controls.Add (cell1);
2011 cell0.ColumnSpan = 2;
2012 cell0.HorizontalAlign = HorizontalAlign.Center;
2014 _createUserWizard.RegisterApplyStyle (cell0, s0);
2019 public void InstantiateIn (Control container) {
2020 Table table = new Table ();
2021 table.ControlStyle.Width = Unit.Percentage (100);
2022 table.ControlStyle.Height = Unit.Percentage (100);
2025 table.Controls.Add (CreateRow (null, null, null, _createUserWizard.TitleTextStyle, null));
2028 table.Controls.Add (CreateRow (null, null, null, _createUserWizard.InstructionTextStyle, null));
2031 TextBox UserName = new TextBox ();
2032 UserName.ID = "UserName";
2033 _createUserWizard.RegisterApplyStyle (UserName, _createUserWizard.TextBoxStyle);
2035 Label UserNameLabel = new Label ();
2036 UserNameLabel.AssociatedControlID = "UserName";
2038 RequiredFieldValidator UserNameRequired = new RequiredFieldValidator ();
2039 UserNameRequired.ID = "UserNameRequired";
2040 // alternatively we can create only required validators
2041 // and reinstantiate collection when relevant property changes
2042 UserNameRequired.EnableViewState = false;
2043 UserNameRequired.ControlToValidate = "UserName";
2044 UserNameRequired.Text = "*";
2045 UserNameRequired.ValidationGroup = _createUserWizard.ID;
2046 _createUserWizard.RegisterApplyStyle (UserNameRequired, _createUserWizard.ValidatorTextStyle);
2048 table.Controls.Add (CreateRow (UserNameLabel, UserName, UserNameRequired, _createUserWizard.LabelStyle, null));
2051 TextBox Password = new TextBox ();
2052 Password.ID = "Password";
2053 Password.TextMode = TextBoxMode.Password;
2054 _createUserWizard.RegisterApplyStyle (Password, _createUserWizard.TextBoxStyle);
2056 Label PasswordLabel = new Label ();
2057 PasswordLabel.AssociatedControlID = "Password";
2059 RequiredFieldValidator PasswordRequired = new RequiredFieldValidator ();
2060 PasswordRequired.ID = "PasswordRequired";
2061 PasswordRequired.EnableViewState = false;
2062 PasswordRequired.ControlToValidate = "Password";
2063 PasswordRequired.Text = "*";
2064 //PasswordRequired.EnableViewState = false;
2065 PasswordRequired.ValidationGroup = _createUserWizard.ID;
2066 _createUserWizard.RegisterApplyStyle (PasswordRequired, _createUserWizard.ValidatorTextStyle);
2068 table.Controls.Add (CreateRow (PasswordLabel, Password, PasswordRequired, _createUserWizard.LabelStyle, null));
2071 table.Controls.Add (CreateRow (new LiteralControl (""), new LiteralControl (""), new LiteralControl (""), null, _createUserWizard.PasswordHintStyle));
2074 TextBox ConfirmPassword = new TextBox ();
2075 ConfirmPassword.ID = "ConfirmPassword";
2076 ConfirmPassword.TextMode = TextBoxMode.Password;
2077 _createUserWizard.RegisterApplyStyle (ConfirmPassword, _createUserWizard.TextBoxStyle);
2079 Label ConfirmPasswordLabel = new Label ();
2080 ConfirmPasswordLabel.AssociatedControlID = "ConfirmPassword";
2082 RequiredFieldValidator ConfirmPasswordRequired = new RequiredFieldValidator ();
2083 ConfirmPasswordRequired.ID = "ConfirmPasswordRequired";
2084 ConfirmPasswordRequired.EnableViewState = false;
2085 ConfirmPasswordRequired.ControlToValidate = "ConfirmPassword";
2086 ConfirmPasswordRequired.Text = "*";
2087 ConfirmPasswordRequired.ValidationGroup = _createUserWizard.ID;
2088 _createUserWizard.RegisterApplyStyle (ConfirmPasswordRequired, _createUserWizard.ValidatorTextStyle);
2090 table.Controls.Add (CreateRow (ConfirmPasswordLabel, ConfirmPassword, ConfirmPasswordRequired, _createUserWizard.LabelStyle, null));
2093 TextBox Email = new TextBox ();
2095 _createUserWizard.RegisterApplyStyle (Email, _createUserWizard.TextBoxStyle);
2097 Label EmailLabel = new Label ();
2098 EmailLabel.AssociatedControlID = "Email";
2100 RequiredFieldValidator EmailRequired = new RequiredFieldValidator ();
2101 EmailRequired.ID = "EmailRequired";
2102 EmailRequired.EnableViewState = false;
2103 EmailRequired.ControlToValidate = "Email";
2104 EmailRequired.Text = "*";
2105 EmailRequired.ValidationGroup = _createUserWizard.ID;
2106 _createUserWizard.RegisterApplyStyle (EmailRequired, _createUserWizard.ValidatorTextStyle);
2108 table.Controls.Add (CreateRow (EmailLabel, Email, EmailRequired, _createUserWizard.LabelStyle, null));
2111 TextBox Question = new TextBox ();
2112 Question.ID = "Question";
2113 _createUserWizard.RegisterApplyStyle (Question, _createUserWizard.TextBoxStyle);
2115 Label QuestionLabel = new Label ();
2116 QuestionLabel.AssociatedControlID = "Question";
2118 RequiredFieldValidator QuestionRequired = new RequiredFieldValidator ();
2119 QuestionRequired.ID = "QuestionRequired";
2120 QuestionRequired.EnableViewState = false;
2121 QuestionRequired.ControlToValidate = "Question";
2122 QuestionRequired.Text = "*";
2123 QuestionRequired.ValidationGroup = _createUserWizard.ID;
2124 _createUserWizard.RegisterApplyStyle (QuestionRequired, _createUserWizard.ValidatorTextStyle);
2126 table.Controls.Add (CreateRow (QuestionLabel, Question, QuestionRequired, _createUserWizard.LabelStyle, null));
2129 TextBox Answer = new TextBox ();
2130 Answer.ID = "Answer";
2131 _createUserWizard.RegisterApplyStyle (Answer, _createUserWizard.TextBoxStyle);
2133 Label AnswerLabel = new Label ();
2134 AnswerLabel.AssociatedControlID = "Answer";
2136 RequiredFieldValidator AnswerRequired = new RequiredFieldValidator ();
2137 AnswerRequired.ID = "AnswerRequired";
2138 AnswerRequired.EnableViewState = false;
2139 AnswerRequired.ControlToValidate = "Answer";
2140 AnswerRequired.Text = "*";
2141 AnswerRequired.ValidationGroup = _createUserWizard.ID;
2142 _createUserWizard.RegisterApplyStyle (AnswerRequired, _createUserWizard.ValidatorTextStyle);
2144 table.Controls.Add (CreateRow (AnswerLabel, Answer, AnswerRequired, _createUserWizard.LabelStyle, null));
2147 CompareValidator PasswordCompare = new CompareValidator ();
2148 PasswordCompare.ID = "PasswordCompare";
2149 PasswordCompare.EnableViewState = false;
2150 PasswordCompare.ControlToCompare = "Password";
2151 PasswordCompare.ControlToValidate = "ConfirmPassword";
2152 PasswordCompare.Display = ValidatorDisplay.Static;
2153 PasswordCompare.ValidationGroup = _createUserWizard.ID;
2154 PasswordCompare.Display = ValidatorDisplay.Dynamic;
2155 _createUserWizard.RegisterApplyStyle (PasswordCompare, _createUserWizard.ValidatorTextStyle);
2157 table.Controls.Add (CreateRow (PasswordCompare, null, null, null, null));
2160 RegularExpressionValidator PasswordRegEx = new RegularExpressionValidator ();
2161 PasswordRegEx.ID = "PasswordRegEx";
2162 PasswordRegEx.EnableViewState = false;
2163 PasswordRegEx.ControlToValidate = "Password";
2164 PasswordRegEx.Display = ValidatorDisplay.Static;
2165 PasswordRegEx.ValidationGroup = _createUserWizard.ID;
2166 PasswordRegEx.Display = ValidatorDisplay.Dynamic;
2167 _createUserWizard.RegisterApplyStyle (PasswordRegEx, _createUserWizard.ValidatorTextStyle);
2169 table.Controls.Add (CreateRow (PasswordRegEx, null, null, null, null));
2172 RegularExpressionValidator EmailRegEx = new RegularExpressionValidator ();
2173 EmailRegEx.ID = "EmailRegEx";
2174 EmailRegEx.EnableViewState = false;
2175 EmailRegEx.ControlToValidate = "Email";
2176 EmailRegEx.Display = ValidatorDisplay.Static;
2177 EmailRegEx.ValidationGroup = _createUserWizard.ID;
2178 EmailRegEx.Display = ValidatorDisplay.Dynamic;
2179 _createUserWizard.RegisterApplyStyle (EmailRegEx, _createUserWizard.ValidatorTextStyle);
2181 table.Controls.Add (CreateRow (EmailRegEx, null, null, null, null));
2184 Label ErrorMessage = new Label ();
2185 ErrorMessage.ID = "ErrorMessage";
2186 ErrorMessage.EnableViewState = false;
2187 _createUserWizard.RegisterApplyStyle (ErrorMessage, _createUserWizard.ValidatorTextStyle);
2189 table.Controls.Add (CreateRow (ErrorMessage, null, null, null, null));
2192 TableRow row13 = CreateRow (new Image (), null, null, null, null);
2194 HyperLink HelpLink = new HyperLink ();
2195 HelpLink.ID = "HelpLink";
2196 _createUserWizard.RegisterApplyStyle (HelpLink, _createUserWizard.HyperLinkStyle);
2197 row13.Cells [0].Controls.Add (HelpLink);
2199 row13.Cells [0].HorizontalAlign = HorizontalAlign.Left;
2200 table.Controls.Add (row13);
2203 container.Controls.Add (table);
2209 sealed class CompleteStepContainer : DefaultContentContainer
2211 CreateUserWizard _createUserWizard;
2213 public CompleteStepContainer (CreateUserWizard createUserWizard)
2214 : base (createUserWizard)
2216 _createUserWizard = createUserWizard;
2219 protected override void UpdateState ()
2222 if (String.IsNullOrEmpty (_createUserWizard.CompleteStep.Title)) {
2223 ((Table) InnerCell.Controls [0]).Rows [0].Visible = false;
2226 ((Table) InnerCell.Controls [0]).Rows [0].Cells [0].Text = _createUserWizard.CompleteStep.Title;
2229 // CompleteSuccessText
2230 if (String.IsNullOrEmpty (_createUserWizard.CompleteSuccessText)) {
2231 ((Table) InnerCell.Controls [0]).Rows [1].Visible = false;
2234 ((Table) InnerCell.Controls [0]).Rows [1].Cells [0].Text = _createUserWizard.CompleteSuccessText;
2238 UpdateNavButtonState ("ContinueButton" + _createUserWizard.ContinueButtonType, _createUserWizard.ContinueButtonText, _createUserWizard.ContinueButtonImageUrl, _createUserWizard.ContinueButtonStyle);
2240 // EditProfileIconUrl
2241 Image img = (Image) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [0];
2242 if (String.IsNullOrEmpty (_createUserWizard.EditProfileIconUrl)) {
2243 img.Visible = false;
2246 img.ImageUrl = _createUserWizard.EditProfileIconUrl;
2247 img.AlternateText = _createUserWizard.EditProfileText;
2251 HyperLink link = (HyperLink) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [1];
2252 if (String.IsNullOrEmpty (_createUserWizard.EditProfileText)) {
2253 link.Visible = false;
2256 link.Text = _createUserWizard.EditProfileText;
2257 link.NavigateUrl = _createUserWizard.EditProfileUrl;
2260 ((Table) InnerCell.Controls [0]).Rows [3].Visible = img.Visible || link.Visible;
2263 void UpdateNavButtonState (string id, string text, string image, Style style)
2265 WebControl b = (WebControl) FindControl (id);
2266 foreach (Control c in b.Parent.Controls)
2269 ((IButtonControl) b).Text = text;
2270 ImageButton imgbtn = b as ImageButton;
2272 imgbtn.ImageUrl = image;
2274 b.ApplyStyle (style);
2278 sealed class CompleteStepTemplate : ITemplate
2280 readonly CreateUserWizard _createUserWizard;
2282 public CompleteStepTemplate (CreateUserWizard createUserWizard)
2284 _createUserWizard = createUserWizard;
2287 #region ITemplate Members
2289 public void InstantiateIn (Control container)
2291 Table table = new Table ();
2294 TableRow row0 = new TableRow ();
2295 TableCell cell00 = new TableCell ();
2297 cell00.HorizontalAlign = HorizontalAlign.Center;
2298 cell00.ColumnSpan = 2;
2299 _createUserWizard.RegisterApplyStyle (cell00, _createUserWizard.TitleTextStyle);
2300 row0.Cells.Add (cell00);
2303 TableRow row1 = new TableRow ();
2304 TableCell cell10 = new TableCell ();
2306 cell10.HorizontalAlign = HorizontalAlign.Center;
2307 _createUserWizard.RegisterApplyStyle (cell10, _createUserWizard.CompleteSuccessTextStyle);
2308 row1.Cells.Add (cell10);
2311 TableRow row2 = new TableRow ();
2312 TableCell cell20 = new TableCell ();
2314 cell20.HorizontalAlign = HorizontalAlign.Right;
2315 cell20.ColumnSpan = 2;
2316 row2.Cells.Add (cell20);
\r
2318 Control [] b = _createUserWizard.CreateButtonSet ("ContinueButton", CreateUserWizard.ContinueButtonCommandName, false, _createUserWizard.ID);
2319 for (int i = 0; i < b.Length; i++)
2320 cell20.Controls.Add (b [i]);
2323 TableRow row3 = new TableRow ();
2324 TableCell cell30 = new TableCell ();
2326 cell30.Controls.Add (new Image ());
2327 HyperLink link = new HyperLink ();
2328 link.ID = "EditProfileLink";
2329 _createUserWizard.RegisterApplyStyle (link, _createUserWizard.HyperLinkStyle);
2330 cell30.Controls.Add (link);
2331 row3.Cells.Add (cell30);
2334 table.Rows.Add (row0);
2335 table.Rows.Add (row1);
2336 table.Rows.Add (row2);
2337 table.Rows.Add (row3);
2339 container.Controls.Add (table);