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.ComponentModel;
37 namespace System.Web.UI.WebControls
39 [BindableAttribute (false)]
40 public class CreateUserWizard : Wizard
42 public static readonly string ContinueButtonCommandName = "Continue";
43 private string _password = "";
44 private string _confirmPassword = "";
45 private MembershipProvider _provider = null;
46 private ITextControl _errorMessageLabel = null;
48 private Style _textBoxStyle = null;
49 private Style _validatorTextStyle = null;
51 private TableItemStyle _completeSuccessTextStyle = null;
52 private TableItemStyle _errorMessageStyle = null;
53 private TableItemStyle _hyperLinkStyle = null;
54 private TableItemStyle _instructionTextStyle = null;
55 private TableItemStyle _labelStyle = null;
56 private TableItemStyle _passwordHintStyle = null;
57 private TableItemStyle _titleTextStyle = null;
58 Style _createUserButtonStyle;
59 Style _continueButtonStyle;
61 private static readonly object CreatedUserEvent = new object ();
62 private static readonly object CreateUserErrorEvent = new object ();
63 private static readonly object CreatingUserEvent = new object ();
64 private static readonly object ContinueButtonClickEvent = new object ();
65 private static readonly object SendingMailEvent = new object ();
66 private static readonly object SendMailErrorEvent = new object ();
68 private CompleteWizardStep _completeWizardStep = null;
69 private CreateUserWizardStep _createUserWizardStep = null;
71 public CreateUserWizard ()
75 #region Public Properties
77 public override int ActiveStepIndex
79 get { return base.ActiveStepIndex; }
80 set { base.ActiveStepIndex = value; }
83 [LocalizableAttribute (true)]
84 [ThemeableAttribute (false)]
85 public virtual string Answer
89 object o = ViewState ["Answer"];
90 return (o == null) ? String.Empty : (string) o;
95 ViewState.Remove ("Answer");
97 ViewState ["Answer"] = value;
101 [LocalizableAttribute (true)]
102 public virtual string AnswerLabelText
106 object o = ViewState ["AnswerLabelText"];
107 return (o == null) ? Locale.GetText ("Security Answer:") : (string) o;
112 ViewState.Remove ("AnswerLabelText");
114 ViewState ["AnswerLabelText"] = value;
118 [LocalizableAttribute (true)]
119 public virtual string AnswerRequiredErrorMessage
123 object o = ViewState ["AnswerRequiredErrorMessage"];
124 return (o == null) ? Locale.GetText ("Security answer is required.") : (string) o;
129 ViewState.Remove ("AnswerRequiredErrorMessage");
131 ViewState ["AnswerRequiredErrorMessage"] = value;
135 [ThemeableAttribute (false)]
136 public virtual bool AutoGeneratePassword
140 object o = ViewState ["AutoGeneratePassword"];
141 return (o == null) ? false : (bool) o;
145 ViewState ["AutoGeneratePassword"] = value;
149 public CompleteWizardStep CompleteStep
153 if (_completeWizardStep == null) {
154 for (int i = 0; i < WizardSteps.Count; i++)
155 if (WizardSteps [i] is CompleteWizardStep) {
156 _completeWizardStep = (CompleteWizardStep) WizardSteps [i];
158 if (_completeWizardStep.Wizard == null)
159 _completeWizardStep.SetWizard (this);
162 return _completeWizardStep;
166 [LocalizableAttribute (true)]
167 public virtual string CompleteSuccessText
171 object o = ViewState ["CompleteSuccessText"];
172 return (o == null) ? Locale.GetText ("Your account has been successfully created.") : (string) o;
177 ViewState.Remove ("CompleteSuccessText");
179 ViewState ["CompleteSuccessText"] = value;
183 public TableItemStyle CompleteSuccessTextStyle
187 if (_completeSuccessTextStyle == null) {
188 _completeSuccessTextStyle = new TableItemStyle ();
189 if (IsTrackingViewState)
190 ((IStateManager) _completeSuccessTextStyle).TrackViewState ();
192 return _completeSuccessTextStyle;
196 public virtual string ConfirmPassword
198 get { return _confirmPassword; }
201 [LocalizableAttribute (true)]
202 public virtual string ConfirmPasswordCompareErrorMessage
206 object o = ViewState ["ConfirmPasswordCompareErrorMessage"];
207 return (o == null) ? Locale.GetText ("The Password and Confirmation Password must match.") : (string) o;
212 ViewState.Remove ("ConfirmPasswordCompareErrorMessage");
214 ViewState ["ConfirmPasswordCompareErrorMessage"] = value;
218 [LocalizableAttribute (true)]
219 public virtual string ConfirmPasswordLabelText
223 object o = ViewState ["ConfirmPasswordLabelText"];
224 return (o == null) ? Locale.GetText ("Confirm Password:") : (string) o;
229 ViewState.Remove ("ConfirmPasswordLabelText");
231 ViewState ["ConfirmPasswordLabelText"] = value;
235 [LocalizableAttribute (true)]
236 public virtual string ConfirmPasswordRequiredErrorMessage
240 object o = ViewState ["ConfirmPasswordRequiredErrorMessage"];
241 return (o == null) ? Locale.GetText ("Confirm Password is required.") : (string) o;
246 ViewState.Remove ("ConfirmPasswordRequiredErrorMessage");
248 ViewState ["ConfirmPasswordRequiredErrorMessage"] = value;
252 public virtual string ContinueButtonImageUrl
254 get { return ViewState.GetString ("ContinueButtonImageUrl", String.Empty); }
255 set { ViewState ["ContinueButtonImageUrl"] = value; }
258 public Style ContinueButtonStyle
261 if (_continueButtonStyle == null) {
262 _continueButtonStyle = new Style ();
263 if (IsTrackingViewState)
264 ((IStateManager) _continueButtonStyle).TrackViewState ();
266 return _continueButtonStyle;
270 [LocalizableAttribute (true)]
271 public virtual string ContinueButtonText
273 get { return ViewState.GetString ("ContinueButtonText", "Continue"); }
274 set { ViewState ["ContinueButtonText"] = value; }
277 public virtual ButtonType ContinueButtonType
280 object v = ViewState ["ContinueButtonType"];
281 return v != null ? (ButtonType) v : ButtonType.Button;
284 ViewState ["ContinueButtonType"] = value;
288 [ThemeableAttribute (false)]
289 public virtual string ContinueDestinationPageUrl
293 object o = ViewState ["ContinueDestinationPageUrl"];
294 return (o == null) ? "" : (string) o;
299 ViewState.Remove ("ContinueDestinationPageUrl");
301 ViewState ["ContinueDestinationPageUrl"] = value;
305 public virtual string CreateUserButtonImageUrl
307 get { return ViewState.GetString ("CreateUserButtonImageUrl", String.Empty); }
308 set { ViewState ["CreateUserButtonImageUrl"] = value; }
311 public Style CreateUserButtonStyle
314 if (_createUserButtonStyle == null) {
315 _createUserButtonStyle = new Style ();
316 if (IsTrackingViewState)
317 ((IStateManager) _createUserButtonStyle).TrackViewState ();
319 return _createUserButtonStyle;
323 [LocalizableAttribute (true)]
324 public virtual string CreateUserButtonText
326 get { return ViewState.GetString ("CreateUserButtonText", "Create User"); }
327 set { ViewState ["CreateUserButtonText"] = value; }
330 public virtual ButtonType CreateUserButtonType
333 object v = ViewState ["CreateUserButtonType"];
334 return v != null ? (ButtonType) v : ButtonType.Button;
337 ViewState ["CreateUserButtonType"] = value;
341 public CreateUserWizardStep CreateUserStep
345 if (_createUserWizardStep == null) {
346 for (int i = 0; i < WizardSteps.Count; i++)
347 if (WizardSteps [i] is CreateUserWizardStep) {
348 _createUserWizardStep = (CreateUserWizardStep) WizardSteps [i];
350 if (_createUserWizardStep.Wizard == null)
351 _createUserWizardStep.SetWizard (this);
354 return _createUserWizardStep;
358 [ThemeableAttribute (false)]
359 public virtual bool DisableCreatedUser
363 object o = ViewState ["DisableCreatedUser"];
364 return (o == null) ? false : (bool) o;
368 ViewState ["DisableCreatedUser"] = value;
372 public override bool DisplaySideBar
375 return ViewState.GetBool ("DisplaySideBar", false);
378 ViewState ["DisplaySideBar"] = value;
379 ChildControlsCreated = false;
383 [LocalizableAttribute (true)]
384 public virtual string DuplicateEmailErrorMessage
388 object o = ViewState ["DuplicateEmailErrorMessage"];
389 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;
394 ViewState.Remove ("DuplicateEmailErrorMessage");
396 ViewState ["DuplicateEmailErrorMessage"] = value;
400 [LocalizableAttribute (true)]
401 public virtual string DuplicateUserNameErrorMessage
405 object o = ViewState ["DuplicateUserNameErrorMessage"];
406 return (o == null) ? Locale.GetText ("Please enter a different user name.") : (string) o;
411 ViewState.Remove ("DuplicateUserNameErrorMessage");
413 ViewState ["DuplicateUserNameErrorMessage"] = value;
417 public virtual string EditProfileIconUrl
421 object o = ViewState ["EditProfileIconUrl"];
422 return (o == null) ? "" : (string) o;
427 ViewState.Remove ("EditProfileIconUrl");
429 ViewState ["EditProfileIconUrl"] = value;
433 [LocalizableAttribute (true)]
434 public virtual string EditProfileText
438 object o = ViewState ["EditProfileText"];
439 return (o == null) ? "" : (string) o;
444 ViewState.Remove ("EditProfileText");
446 ViewState ["EditProfileText"] = value;
450 public virtual string EditProfileUrl
454 object o = ViewState ["EditProfileUrl"];
455 return (o == null) ? "" : (string) o;
460 ViewState.Remove ("EditProfileUrl");
462 ViewState ["EditProfileUrl"] = value;
466 public virtual string Email
470 object o = ViewState ["Email"];
471 return (o == null) ? String.Empty : (string) o;
476 ViewState.Remove ("Email");
478 ViewState ["Email"] = value;
482 [LocalizableAttribute (true)]
483 public virtual string EmailLabelText
487 object o = ViewState ["EmailLabelText"];
488 return (o == null) ? Locale.GetText ("E-mail:") : (string) o;
493 ViewState.Remove ("EmailLabelText");
495 ViewState ["EmailLabelText"] = value;
499 public virtual string EmailRegularExpression
503 object o = ViewState ["EmailRegularExpression"];
504 return (o == null) ? "" : (string) o;
509 ViewState.Remove ("EmailRegularExpression");
511 ViewState ["EmailRegularExpression"] = value;
515 public virtual string EmailRegularExpressionErrorMessage
519 object o = ViewState ["EmailRegularExpressionErrorMessage"];
520 return (o == null) ? Locale.GetText ("Please enter a different e-mail.") : (string) o;
525 ViewState.Remove ("EmailRegularExpressionErrorMessage");
527 ViewState ["EmailRegularExpressionErrorMessage"] = value;
531 [LocalizableAttribute (true)]
532 public virtual string EmailRequiredErrorMessage
536 object o = ViewState ["EmailRequiredErrorMessage"];
537 return (o == null) ? Locale.GetText ("E-mail is required.") : (string) o;
542 ViewState.Remove ("EmailRequiredErrorMessage");
544 ViewState ["EmailRequiredErrorMessage"] = value;
548 public TableItemStyle ErrorMessageStyle
552 if (_errorMessageStyle == null) {
553 _errorMessageStyle = new TableItemStyle ();
554 if (IsTrackingViewState)
555 ((IStateManager) _errorMessageStyle).TrackViewState ();
557 return _errorMessageStyle;
561 public virtual string HelpPageIconUrl
565 object o = ViewState ["HelpPageIconUrl"];
566 return (o == null) ? "" : (string) o;
571 ViewState.Remove ("HelpPageIconUrl");
573 ViewState ["HelpPageIconUrl"] = value;
577 [LocalizableAttribute (true)]
578 public virtual string HelpPageText
582 object o = ViewState ["HelpPageText"];
583 return (o == null) ? "" : (string) o;
588 ViewState.Remove ("HelpPageText");
590 ViewState ["HelpPageText"] = value;
594 public virtual string HelpPageUrl
598 object o = ViewState ["HelpPageUrl"];
599 return (o == null) ? "" : (string) o;
604 ViewState.Remove ("HelpPageUrl");
606 ViewState ["HelpPageUrl"] = value;
610 public TableItemStyle HyperLinkStyle
614 if (_hyperLinkStyle == null) {
615 _hyperLinkStyle = new TableItemStyle ();
616 if (IsTrackingViewState)
617 ((IStateManager) _hyperLinkStyle).TrackViewState ();
619 return _hyperLinkStyle;
623 [LocalizableAttribute (true)]
624 public virtual string InstructionText
628 object o = ViewState ["InstructionText"];
629 return (o == null) ? "" : (string) o;
634 ViewState.Remove ("InstructionText");
636 ViewState ["InstructionText"] = value;
640 public TableItemStyle InstructionTextStyle
644 if (_instructionTextStyle == null) {
645 _instructionTextStyle = new TableItemStyle ();
646 if (IsTrackingViewState)
647 ((IStateManager) _instructionTextStyle).TrackViewState ();
649 return _instructionTextStyle;
653 [LocalizableAttribute (true)]
654 public virtual string InvalidAnswerErrorMessage
658 object o = ViewState ["InvalidAnswerErrorMessage"];
659 return (o == null) ? Locale.GetText ("Please enter a different security answer.") : (string) o;
664 ViewState.Remove ("InvalidAnswerErrorMessage");
666 ViewState ["InvalidAnswerErrorMessage"] = value;
670 [LocalizableAttribute (true)]
671 public virtual string InvalidEmailErrorMessage
675 object o = ViewState ["InvalidEmailErrorMessage"];
676 return (o == null) ? Locale.GetText ("Please enter a valid e-mail address.") : (string) o;
681 ViewState.Remove ("InvalidEmailErrorMessage");
683 ViewState ["InvalidEmailErrorMessage"] = value;
687 [MonoTODO ("take the values from membership provider")]
688 [LocalizableAttribute (true)]
689 public virtual string InvalidPasswordErrorMessage
693 object o = ViewState ["InvalidPasswordErrorMessage"];
694 return (o == null) ? Locale.GetText ("Password length minimum: {0}. Non-alphanumeric characters required: {1}.") : (string) o;
699 ViewState.Remove ("InvalidPasswordErrorMessage");
701 ViewState ["InvalidPasswordErrorMessage"] = value;
705 [LocalizableAttribute (true)]
706 public virtual string InvalidQuestionErrorMessage
710 object o = ViewState ["InvalidQuestionErrorMessage"];
711 return (o == null) ? Locale.GetText ("Please enter a different security question.") : (string) o;
716 ViewState.Remove ("InvalidQuestionErrorMessage");
718 ViewState ["InvalidQuestionErrorMessage"] = value;
722 public TableItemStyle LabelStyle
726 if (_labelStyle == null) {
727 _labelStyle = new TableItemStyle ();
728 if (IsTrackingViewState)
729 ((IStateManager) _labelStyle).TrackViewState ();
735 [ThemeableAttribute (false)]
736 public virtual bool LoginCreatedUser
740 object o = ViewState ["LoginCreatedUser"];
741 return (o == null) ? true : (bool) o;
745 ViewState ["LoginCreatedUser"] = value;
749 //[MonoTODO ("Sending mail functionality is not implemented")]
750 //[ThemeableAttribute (false)]
751 //public MailDefinition MailDefinition
753 // get { throw new NotImplementedException (); }
756 [ThemeableAttribute (false)]
757 public virtual string MembershipProvider
761 object o = ViewState ["MembershipProvider"];
762 return (o == null) ? "" : (string) o;
767 ViewState.Remove ("MembershipProvider");
769 ViewState ["MembershipProvider"] = value;
775 internal virtual MembershipProvider MembershipProviderInternal
779 if (_provider == null)
780 InitMemberShipProvider ();
786 public virtual string Password
788 get { return _password; }
791 public TableItemStyle PasswordHintStyle
795 if (_passwordHintStyle == null) {
796 _passwordHintStyle = new TableItemStyle ();
797 if (IsTrackingViewState)
798 ((IStateManager) _passwordHintStyle).TrackViewState ();
800 return _passwordHintStyle;
804 [LocalizableAttribute (true)]
805 public virtual string PasswordHintText
809 object o = ViewState ["PasswordHintText"];
810 return (o == null) ? "" : (string) o;
815 ViewState.Remove ("PasswordHintText");
817 ViewState ["PasswordHintText"] = value;
821 [LocalizableAttribute (true)]
822 public virtual string PasswordLabelText
826 object o = ViewState ["PasswordLabelText"];
827 return (o == null) ? Locale.GetText ("Password:") : (string) o;
832 ViewState.Remove ("PasswordLabelText");
834 ViewState ["PasswordLabelText"] = value;
838 public virtual string PasswordRegularExpression
842 object o = ViewState ["PasswordRegularExpression"];
843 return (o == null) ? "" : (string) o;
848 ViewState.Remove ("PasswordRegularExpression");
850 ViewState ["PasswordRegularExpression"] = value;
854 public virtual string PasswordRegularExpressionErrorMessage
858 object o = ViewState ["PasswordRegularExpressionErrorMessage"];
859 return (o == null) ? Locale.GetText ("Please enter a different password.") : (string) o;
864 ViewState.Remove ("PasswordRegularExpressionErrorMessage");
866 ViewState ["PasswordRegularExpressionErrorMessage"] = value;
870 [LocalizableAttribute (true)]
871 public virtual string PasswordRequiredErrorMessage
875 object o = ViewState ["PasswordRequiredErrorMessage"];
876 return (o == null) ? Locale.GetText ("Password is required.") : (string) o;
881 ViewState.Remove ("PasswordRequiredErrorMessage");
883 ViewState ["PasswordRequiredErrorMessage"] = value;
887 [LocalizableAttribute (true)]
888 [ThemeableAttribute (false)]
889 public virtual string Question
893 object o = ViewState ["Question"];
894 return (o == null) ? String.Empty : (string) o;
899 ViewState.Remove ("Question");
901 ViewState ["Question"] = value;
905 [LocalizableAttribute (true)]
906 public virtual string QuestionLabelText
910 object o = ViewState ["QuestionLabelText"];
911 return (o == null) ? Locale.GetText ("Security Question:") : (string) o;
916 ViewState.Remove ("QuestionLabelText");
918 ViewState ["QuestionLabelText"] = value;
922 [LocalizableAttribute (true)]
923 public virtual string QuestionRequiredErrorMessage
927 object o = ViewState ["QuestionRequiredErrorMessage"];
928 return (o == null) ? Locale.GetText ("Security question is required.") : (string) o;
933 ViewState.Remove ("QuestionRequiredErrorMessage");
935 ViewState ["QuestionRequiredErrorMessage"] = value;
939 [ThemeableAttribute (false)]
940 public virtual bool RequireEmail
944 object o = ViewState ["RequireEmail"];
945 return (o == null) ? true : (bool) o;
949 ViewState ["RequireEmail"] = value;
953 [MonoTODO ("doesnt work")]
954 public override string SkipLinkText
958 object o = ViewState ["SkipLinkText"];
959 return (o == null) ? "" : (string) o;
964 ViewState.Remove ("SkipLinkText");
966 ViewState ["SkipLinkText"] = value;
970 public Style TextBoxStyle
974 if (_textBoxStyle == null) {
975 _textBoxStyle = new Style ();
976 if (IsTrackingViewState)
977 ((IStateManager) _textBoxStyle).TrackViewState ();
979 return _textBoxStyle;
983 public TableItemStyle TitleTextStyle
987 if (_titleTextStyle == null) {
988 _titleTextStyle = new TableItemStyle ();
989 if (IsTrackingViewState)
990 ((IStateManager) _titleTextStyle).TrackViewState ();
992 return _titleTextStyle;
996 [LocalizableAttribute (true)]
997 public virtual string UnknownErrorMessage
1001 object o = ViewState ["UnknownErrorMessage"];
1002 return (o == null) ? Locale.GetText ("Your account was not created. Please try again.") : (string) o;
1007 ViewState.Remove ("UnknownErrorMessage");
1009 ViewState ["UnknownErrorMessage"] = value;
1013 public virtual string UserName
1017 object o = ViewState ["UserName"];
1018 return (o == null) ? String.Empty : (string) o;
1023 ViewState.Remove ("UserName");
1025 ViewState ["UserName"] = value;
1029 [LocalizableAttribute (true)]
1030 public virtual string UserNameLabelText
1034 object o = ViewState ["UserNameLabelText"];
1035 return (o == null) ? Locale.GetText ("User Name:") : (string) o;
1040 ViewState.Remove ("UserNameLabelText");
1042 ViewState ["UserNameLabelText"] = value;
1046 [LocalizableAttribute (true)]
1047 public virtual string UserNameRequiredErrorMessage
1051 object o = ViewState ["UserNameRequiredErrorMessage"];
1052 return (o == null) ? Locale.GetText ("User Name is required.") : (string) o;
1057 ViewState.Remove ("UserNameRequiredErrorMessage");
1059 ViewState ["UserNameRequiredErrorMessage"] = value;
1063 public Style ValidatorTextStyle
1067 if (_validatorTextStyle == null) {
1068 _validatorTextStyle = new Style ();
1069 if (IsTrackingViewState)
1070 ((IStateManager) _validatorTextStyle).TrackViewState ();
1072 return _validatorTextStyle;
1076 [ThemeableAttribute (false)]
1077 public override WizardStepCollection WizardSteps
1079 get { return base.WizardSteps; }
1084 #region Protected Properties
1086 protected internal bool QuestionAndAnswerRequired
1088 get { return MembershipProviderInternal.RequiresQuestionAndAnswer; }
1091 public event EventHandler ContinueButtonClick
1093 add { Events.AddHandler (ContinueButtonClickEvent, value); }
1094 remove { Events.RemoveHandler (ContinueButtonClickEvent, value); }
1097 public event EventHandler CreatedUser
1099 add { Events.AddHandler (CreatedUserEvent, value); }
1100 remove { Events.RemoveHandler (CreatedUserEvent, value); }
1103 public event CreateUserErrorEventHandler CreateUserError
1105 add { Events.AddHandler (CreateUserErrorEvent, value); }
1106 remove { Events.RemoveHandler (CreateUserErrorEvent, value); }
1109 public event LoginCancelEventHandler CreatingUser
1111 add { Events.AddHandler (CreatingUserEvent, value); }
1112 remove { Events.RemoveHandler (CreatingUserEvent, value); }
1115 public event MailMessageEventHandler SendingMail
1117 add { Events.AddHandler (SendingMailEvent, value); }
1118 remove { Events.RemoveHandler (SendingMailEvent, value); }
1121 public event SendMailErrorEventHandler SendMailError
1123 add { Events.AddHandler (SendMailErrorEvent, value); }
1124 remove { Events.RemoveHandler (SendMailErrorEvent, value); }
1130 #region Internal Properties
1132 internal override void InstantiateTemplateStep (TemplatedWizardStep step)
1134 if (step is CreateUserWizardStep) {
1135 InstantiateCreateUserWizardStep ((CreateUserWizardStep) step);
1137 else if (step is CompleteWizardStep) {
1138 InstantiateCompleteWizardStep ((CompleteWizardStep) step);
1141 base.InstantiateTemplateStep (step);
1145 private void InstantiateCompleteWizardStep (CompleteWizardStep step)
1147 CompleteStepContainer contentTemplateContainer = new CompleteStepContainer (this);
1148 if (step.ContentTemplate != null) {
1149 step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1152 new CompleteStepTemplate (this).InstantiateIn (contentTemplateContainer.InnerCell);
1153 contentTemplateContainer.ConfirmDefaultTemplate ();
1156 step.ContentTemplateContainer = contentTemplateContainer;
1157 step.Controls.Clear ();
1158 step.Controls.Add (contentTemplateContainer);
1160 BaseWizardNavigationContainer customNavigationTemplateContainer = new BaseWizardNavigationContainer ();
1161 if (step.CustomNavigationTemplate != null) {
1162 step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1163 RegisterCustomNavigation (step, customNavigationTemplateContainer);
1165 step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1168 void InstantiateCreateUserWizardStep (CreateUserWizardStep step)
1170 CreateUserStepContainer contentTemplateContainer = new CreateUserStepContainer (this);
1171 if (step.ContentTemplate != null) {
1172 step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1175 new CreateUserStepTemplate (this).InstantiateIn (contentTemplateContainer.InnerCell);
1176 contentTemplateContainer.ConfirmDefaultTemplate ();
1177 contentTemplateContainer.EnsureValidatorsState ();
1180 step.ContentTemplateContainer = contentTemplateContainer;
1181 step.Controls.Clear ();
1182 step.Controls.Add (contentTemplateContainer);
1184 CreateUserNavigationContainer customNavigationTemplateContainer = new CreateUserNavigationContainer (this);
1185 if (step.CustomNavigationTemplate != null) {
1186 step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1189 new CreateUserStepNavigationTemplate (this).InstantiateIn (customNavigationTemplateContainer);
1190 customNavigationTemplateContainer.ConfirmDefaultTemplate ();
1192 RegisterCustomNavigation (step, customNavigationTemplateContainer);
1194 step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1197 internal override ITemplate SideBarItemTemplate
1199 get { return new SideBarLabelTemplate (this); }
1204 #region Protected Methods
1206 protected internal override void CreateChildControls ()
1208 if (CreateUserStep == null)
1209 WizardSteps.AddAt (0, new CreateUserWizardStep ());
1211 if (CompleteStep == null)
1212 WizardSteps.AddAt (WizardSteps.Count, new CompleteWizardStep ());
1214 base.CreateChildControls ();
1217 protected override void CreateControlHierarchy ()
1219 base.CreateControlHierarchy ();
1221 CreateUserStepContainer container = CreateUserStep.ContentTemplateContainer as CreateUserStepContainer;
1223 if (container != null) {
1224 IEditableTextControl editable;
1225 editable = container.UserNameTextBox as IEditableTextControl;
1227 if (editable != null)
1228 editable.TextChanged += new EventHandler (UserName_TextChanged);
1230 if (!AutoGeneratePassword) {
1231 editable = container.PasswordTextBox as IEditableTextControl;
1233 if (editable != null)
1234 editable.TextChanged += new EventHandler (Password_TextChanged);
1236 editable = container.ConfirmPasswordTextBox as IEditableTextControl;
1238 if (editable != null)
1239 editable.TextChanged += new EventHandler (ConfirmPassword_TextChanged);
1243 editable = container.EmailTextBox as IEditableTextControl;
1245 if (editable != null)
1246 editable.TextChanged += new EventHandler (Email_TextChanged);
1249 if (QuestionAndAnswerRequired) {
1250 editable = container.QuestionTextBox as IEditableTextControl;
1252 if (editable != null)
1253 editable.TextChanged += new EventHandler (Question_TextChanged);
1255 editable = container.AnswerTextBox as IEditableTextControl;
1257 if (editable != null)
1258 editable.TextChanged += new EventHandler (Answer_TextChanged);
1261 _errorMessageLabel = container.ErrorMessageLabel;
1265 [MonoTODO ("Not Implemented")]
1266 protected override IDictionary GetDesignModeState ()
1268 throw new NotImplementedException ();
1271 protected override bool OnBubbleEvent (object source, EventArgs e)
1273 CommandEventArgs args = e as CommandEventArgs;
1274 if (e != null && args.CommandName == ContinueButtonCommandName) {
1275 ProcessContinueEvent ();
1278 return base.OnBubbleEvent (source, e);
1281 private void ProcessContinueEvent () {
1282 OnContinueButtonClick (EventArgs.Empty);
1284 if (ContinueDestinationPageUrl.Length > 0) {
1285 Context.Response.Redirect (ContinueDestinationPageUrl);
1289 protected virtual void OnContinueButtonClick (EventArgs e)
1291 if (Events != null) {
1292 EventHandler eh = (EventHandler) Events [ContinueButtonClickEvent];
1293 if (eh != null) eh (this, e);
1297 protected virtual void OnCreatedUser (EventArgs e)
1299 if (Events != null) {
1300 EventHandler eh = (EventHandler) Events [CreatedUserEvent];
1301 if (eh != null) eh (this, e);
1305 protected virtual void OnCreateUserError (CreateUserErrorEventArgs e)
1307 if (Events != null) {
1308 CreateUserErrorEventHandler eh = (CreateUserErrorEventHandler) Events [CreateUserErrorEvent];
1309 if (eh != null) eh (this, e);
1313 protected virtual void OnCreatingUser (LoginCancelEventArgs e)
1315 if (Events != null) {
1316 LoginCancelEventHandler eh = (LoginCancelEventHandler) Events [CreatingUserEvent];
1317 if (eh != null) eh (this, e);
1321 protected override void OnNextButtonClick (WizardNavigationEventArgs e)
1323 if (ActiveStep == CreateUserStep) {
1324 bool userCreated = CreateUser ();
1328 if (LoginCreatedUser)
1331 base.OnNextButtonClick (e);
1334 protected internal override void OnPreRender (EventArgs e)
1336 base.OnPreRender (e);
1339 protected virtual void OnSendingMail (MailMessageEventArgs e)
1341 if (Events != null) {
1342 MailMessageEventHandler eh = (MailMessageEventHandler) Events [SendingMailEvent];
1343 if (eh != null) eh (this, e);
1347 protected virtual void OnSendMailError (SendMailErrorEventArgs e)
1349 if (Events != null) {
1350 SendMailErrorEventHandler eh = (SendMailErrorEventHandler) Events [SendMailErrorEvent];
1351 if (eh != null) eh (this, e);
1355 protected override void LoadViewState (object savedState)
1357 if (savedState == null) {
1358 base.LoadViewState (null);
1362 object [] states = (object []) savedState;
1363 base.LoadViewState (states [0]);
1365 if (states [1] != null)
1366 ((IStateManager) TextBoxStyle).LoadViewState (states [1]);
1367 if (states [2] != null)
1368 ((IStateManager) ValidatorTextStyle).LoadViewState (states [2]);
1369 if (states [3] != null)
1370 ((IStateManager) CompleteSuccessTextStyle).LoadViewState (states [3]);
1371 if (states [4] != null)
1372 ((IStateManager) ErrorMessageStyle).LoadViewState (states [4]);
1373 if (states [5] != null)
1374 ((IStateManager) HyperLinkStyle).LoadViewState (states [5]);
1375 if (states [6] != null)
1376 ((IStateManager) InstructionTextStyle).LoadViewState (states [6]);
1377 if (states [7] != null)
1378 ((IStateManager) LabelStyle).LoadViewState (states [7]);
1379 if (states [8] != null)
1380 ((IStateManager) PasswordHintStyle).LoadViewState (states [8]);
1381 if (states [9] != null)
1382 ((IStateManager) TitleTextStyle).LoadViewState (states [9]);
1383 if (states [10] != null)
1384 ((IStateManager) CreateUserButtonStyle).LoadViewState (states [10]);
1385 if (states [11] != null)
1386 ((IStateManager) ContinueButtonStyle).LoadViewState (states [11]);
1388 ((CreateUserStepContainer) CreateUserStep.ContentTemplateContainer).EnsureValidatorsState ();
1391 protected override object SaveViewState ()
1393 object [] state = new object [12];
1394 state [0] = base.SaveViewState ();
1396 if (_textBoxStyle != null)
1397 state [1] = ((IStateManager) _textBoxStyle).SaveViewState ();
1398 if (_validatorTextStyle != null)
1399 state [2] = ((IStateManager) _validatorTextStyle).SaveViewState ();
1400 if (_completeSuccessTextStyle != null)
1401 state [3] = ((IStateManager) _completeSuccessTextStyle).SaveViewState ();
1402 if (_errorMessageStyle != null)
1403 state [4] = ((IStateManager) _errorMessageStyle).SaveViewState ();
1404 if (_hyperLinkStyle != null)
1405 state [5] = ((IStateManager) _hyperLinkStyle).SaveViewState ();
1406 if (_instructionTextStyle != null)
1407 state [6] = ((IStateManager) _instructionTextStyle).SaveViewState ();
1408 if (_labelStyle != null)
1409 state [7] = ((IStateManager) _labelStyle).SaveViewState ();
1410 if (_passwordHintStyle != null)
1411 state [8] = ((IStateManager) _passwordHintStyle).SaveViewState ();
1412 if (_titleTextStyle != null)
1413 state [9] = ((IStateManager) _titleTextStyle).SaveViewState ();
1414 if (_createUserButtonStyle != null)
1415 state [10] = ((IStateManager) _createUserButtonStyle).SaveViewState ();
1416 if (_continueButtonStyle != null)
1417 state [11] = ((IStateManager) _continueButtonStyle).SaveViewState ();
1419 for (int n = 0; n < state.Length; n++)
1420 if (state [n] != null)
1426 [MonoTODO ("for design-time usage - no more details available")]
1427 protected override void SetDesignModeState (IDictionary data)
1429 base.SetDesignModeState (data);
1432 protected override void TrackViewState ()
1434 base.TrackViewState ();
1435 if (_textBoxStyle != null)
1436 ((IStateManager) _textBoxStyle).TrackViewState ();
1437 if (_validatorTextStyle != null)
1438 ((IStateManager) _validatorTextStyle).TrackViewState ();
1439 if (_completeSuccessTextStyle != null)
1440 ((IStateManager) _completeSuccessTextStyle).TrackViewState ();
1441 if (_errorMessageStyle != null)
1442 ((IStateManager) _errorMessageStyle).TrackViewState ();
1443 if (_hyperLinkStyle != null)
1444 ((IStateManager) _hyperLinkStyle).TrackViewState ();
1445 if (_instructionTextStyle != null)
1446 ((IStateManager) _instructionTextStyle).TrackViewState ();
1447 if (_labelStyle != null)
1448 ((IStateManager) _labelStyle).TrackViewState ();
1449 if (_passwordHintStyle != null)
1450 ((IStateManager) _passwordHintStyle).TrackViewState ();
1451 if (_titleTextStyle != null)
1452 ((IStateManager) _titleTextStyle).TrackViewState ();
1453 if (_createUserButtonStyle != null)
1454 ((IStateManager) _createUserButtonStyle).TrackViewState ();
1455 if (_continueButtonStyle != null)
1456 ((IStateManager) _continueButtonStyle).TrackViewState ();
1461 #region Private event handlers
1463 private void UserName_TextChanged (object sender, EventArgs e)
1465 UserName = ((ITextControl) sender).Text;
1468 private void Password_TextChanged (object sender, EventArgs e)
1470 _password = ((ITextControl) sender).Text;
1473 private void ConfirmPassword_TextChanged (object sender, EventArgs e)
1475 _confirmPassword = ((ITextControl) sender).Text;
1478 private void Email_TextChanged (object sender, EventArgs e)
1480 Email = ((ITextControl) sender).Text;
1483 private void Question_TextChanged (object sender, EventArgs e)
1485 Question = ((ITextControl) sender).Text;
1488 private void Answer_TextChanged (object sender, EventArgs e)
1490 Answer = ((ITextControl) sender).Text;
1495 #region Private Methods
1497 private void InitMemberShipProvider ()
1499 string mp = MembershipProvider;
1500 _provider = (mp.Length == 0) ? _provider = Membership.Provider : Membership.Providers [mp];
1501 if (_provider == null)
1502 throw new HttpException (Locale.GetText ("No provider named '{0}' could be found.", mp));
1505 private bool CreateUser ()
1510 if (AutoGeneratePassword)
1511 _password = GeneratePassword ();
1513 OnCreatingUser (new LoginCancelEventArgs (false));
1515 MembershipCreateStatus status;
1516 MembershipUser newUser = MembershipProviderInternal.CreateUser (
1517 UserName, Password, Email, Question, Answer, !DisableCreatedUser, null, out status);
1519 if ((newUser != null) && (status == MembershipCreateStatus.Success)) {
1520 OnCreatedUser (new EventArgs ());
1525 case MembershipCreateStatus.DuplicateUserName:
1526 ShowErrorMessage (DuplicateUserNameErrorMessage);
1529 case MembershipCreateStatus.InvalidPassword:
1530 ShowErrorMessage (String.Format (InvalidPasswordErrorMessage, MembershipProviderInternal.MinRequiredPasswordLength, MembershipProviderInternal.MinRequiredNonAlphanumericCharacters));
1533 case MembershipCreateStatus.DuplicateEmail:
1534 ShowErrorMessage (DuplicateEmailErrorMessage);
1537 case MembershipCreateStatus.InvalidEmail:
1538 ShowErrorMessage (InvalidEmailErrorMessage);
1541 case MembershipCreateStatus.InvalidQuestion:
1542 ShowErrorMessage (InvalidQuestionErrorMessage);
1545 case MembershipCreateStatus.InvalidAnswer:
1546 ShowErrorMessage (InvalidAnswerErrorMessage);
1549 case MembershipCreateStatus.UserRejected:
1550 case MembershipCreateStatus.InvalidUserName:
1551 case MembershipCreateStatus.ProviderError:
1552 case MembershipCreateStatus.InvalidProviderUserKey:
1553 ShowErrorMessage (UnknownErrorMessage);
1559 OnCreateUserError (new CreateUserErrorEventArgs (status));
1564 private void Login ()
1566 bool userValidated = MembershipProviderInternal.ValidateUser (UserName, Password);
1568 FormsAuthentication.SetAuthCookie (UserName, false);
1571 private void ShowErrorMessage (string errorMessage)
1573 if (_errorMessageLabel != null)
1574 _errorMessageLabel.Text = errorMessage;
1577 private string GeneratePassword ()
1579 return Membership.GeneratePassword (8, 3);
1584 #region SideBarLabelTemplate
1586 class SideBarLabelTemplate : ITemplate
1590 public SideBarLabelTemplate (Wizard wizard)
1592 this.wizard = wizard;
1595 public void InstantiateIn (Control control)
1597 Label b = new Label ();
1598 wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1599 control.Controls.Add (b);
1600 control.DataBinding += Bound;
1603 void Bound (object s, EventArgs args)
1605 WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1607 Control c = (Control) s;
1608 Label b = (Label) c.Controls [0];
1609 b.ID = SideBarButtonID;
1610 b.Text = step.Title;
1617 sealed class CreateUserNavigationContainer : DefaultNavigationContainer
1619 CreateUserWizard _createUserWizard;
1621 public CreateUserNavigationContainer (CreateUserWizard createUserWizard)
1622 : base (createUserWizard)
1624 _createUserWizard = createUserWizard;
1627 protected override void UpdateState ()
1630 if (_createUserWizard.AllowNavigationToStep (_createUserWizard.ActiveStepIndex - 1)) {
1631 UpdateNavButtonState (Wizard.StepPreviousButtonID + Wizard.StepPreviousButtonType, Wizard.StepPreviousButtonText, Wizard.StepPreviousButtonImageUrl, Wizard.StepPreviousButtonStyle);
1634 ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1638 UpdateNavButtonState (Wizard.StepNextButtonID + _createUserWizard.CreateUserButtonType, _createUserWizard.CreateUserButtonText, _createUserWizard.CreateUserButtonImageUrl, _createUserWizard.CreateUserButtonStyle);
1641 if (Wizard.DisplayCancelButton) {
1642 UpdateNavButtonState (Wizard.CancelButtonID + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1645 ((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
1650 sealed class CreateUserStepNavigationTemplate : ITemplate
1652 readonly CreateUserWizard _createUserWizard;
1654 public CreateUserStepNavigationTemplate (CreateUserWizard createUserWizard) {
1655 _createUserWizard = createUserWizard;
1658 #region ITemplate Members
1660 public void InstantiateIn (Control container) {
1661 Table t = new Table ();
1664 t.Width = Unit.Percentage (100);
1665 t.Height = Unit.Percentage (100);
1666 TableRow row = new TableRow ();
1668 AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.StepPreviousButtonID, Wizard.MovePreviousCommandName, false));
1669 AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.StepNextButtonID, Wizard.MoveNextCommandName));
1670 AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.CancelButtonID, Wizard.CancelCommandName, false));
1673 container.Controls.Add (t);
1676 void AddButtonCell (TableRow row, params Control [] controls)
1678 TableCell cell = new TableCell ();
1679 cell.HorizontalAlign = HorizontalAlign.Right;
1680 for (int i = 0; i < controls.Length; i++)
1681 cell.Controls.Add (controls[i]);
1682 row.Cells.Add (cell);
1688 sealed class CreateUserStepContainer : DefaultContentContainer
1690 CreateUserWizard _createUserWizard;
1692 public CreateUserStepContainer (CreateUserWizard createUserWizard)
1693 : base (createUserWizard)
1695 _createUserWizard = createUserWizard;
1698 public Control UserNameTextBox {
1700 Control c = FindControl ("UserName");
1702 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID UserName for the username.");
1707 public Control PasswordTextBox {
1709 Control c = FindControl ("Password");
1711 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Password for the new password, this is required if AutoGeneratePassword = true.");
1716 public Control ConfirmPasswordTextBox {
1718 Control c = FindControl ("Password");
1722 public Control EmailTextBox {
1724 Control c = FindControl ("Email");
1726 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Email for the e-mail, this is required if RequireEmail = true.");
1731 public Control QuestionTextBox {
1733 Control c = FindControl ("Question");
1735 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.");
1740 public Control AnswerTextBox {
1742 Control c = FindControl ("Answer");
1744 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.");
1749 public ITextControl ErrorMessageLabel {
1750 get { return FindControl ("ErrorMessage") as ITextControl; }
1753 protected override void UpdateState () {
1755 if (String.IsNullOrEmpty (_createUserWizard.CreateUserStep.Title)) {
1756 ((Table) InnerCell.Controls [0]).Rows [0].Visible = false;
1759 ((Table) InnerCell.Controls [0]).Rows [0].Cells [0].Text = _createUserWizard.CreateUserStep.Title;
1762 // Row #1 - InstructionText
1763 if (String.IsNullOrEmpty (_createUserWizard.InstructionText)) {
1764 ((Table) InnerCell.Controls [0]).Rows [1].Visible = false;
1767 ((Table) InnerCell.Controls [0]).Rows [1].Cells [0].Text = _createUserWizard.InstructionText;
1771 Label UserNameLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [2].Cells [0].Controls [0];
1772 UserNameLabel.Text = _createUserWizard.UserNameLabelText;
1774 RequiredFieldValidator UserNameRequired = (RequiredFieldValidator) FindControl ("UserNameRequired");
1775 UserNameRequired.ErrorMessage = _createUserWizard.UserNameRequiredErrorMessage;
1776 UserNameRequired.ToolTip = _createUserWizard.UserNameRequiredErrorMessage;
1778 if (_createUserWizard.AutoGeneratePassword) {
1779 ((Table) InnerCell.Controls [0]).Rows [3].Visible = false;
1780 ((Table) InnerCell.Controls [0]).Rows [4].Visible = false;
1781 ((Table) InnerCell.Controls [0]).Rows [5].Visible = false;
1785 Label PasswordLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [0];
1786 PasswordLabel.Text = _createUserWizard.PasswordLabelText;
1788 RequiredFieldValidator PasswordRequired = (RequiredFieldValidator) FindControl ("PasswordRequired");
1789 PasswordRequired.ErrorMessage = _createUserWizard.PasswordRequiredErrorMessage;
1790 PasswordRequired.ToolTip = _createUserWizard.PasswordRequiredErrorMessage;
1793 if (String.IsNullOrEmpty (_createUserWizard.PasswordHintText)) {
1794 ((Table) InnerCell.Controls [0]).Rows [4].Visible = false;
1797 ((Table) InnerCell.Controls [0]).Rows [4].Cells [1].Text = _createUserWizard.PasswordHintText;
1801 Label ConfirmPasswordLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [5].Cells [0].Controls [0];
1802 ConfirmPasswordLabel.Text = _createUserWizard.ConfirmPasswordLabelText;
1804 RequiredFieldValidator ConfirmPasswordRequired = (RequiredFieldValidator) FindControl ("ConfirmPasswordRequired");
1805 ConfirmPasswordRequired.ErrorMessage = _createUserWizard.ConfirmPasswordRequiredErrorMessage;
1806 ConfirmPasswordRequired.ToolTip = _createUserWizard.ConfirmPasswordRequiredErrorMessage;
1810 if (_createUserWizard.RequireEmail) {
1811 Label EmailLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [6].Cells [0].Controls [0];
1812 EmailLabel.Text = _createUserWizard.EmailLabelText;
1814 RequiredFieldValidator EmailRequired = (RequiredFieldValidator) FindControl ("EmailRequired");
1815 EmailRequired.ErrorMessage = _createUserWizard.EmailRequiredErrorMessage;
1816 EmailRequired.ToolTip = _createUserWizard.EmailRequiredErrorMessage;
1819 ((Table) InnerCell.Controls [0]).Rows [6].Visible = false;
1822 if (_createUserWizard.QuestionAndAnswerRequired) {
1824 Label QuestionLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [7].Cells [0].Controls [0];
1825 QuestionLabel.Text = _createUserWizard.QuestionLabelText;
1827 RequiredFieldValidator QuestionRequired = (RequiredFieldValidator) FindControl ("QuestionRequired");
1828 QuestionRequired.ErrorMessage = _createUserWizard.QuestionRequiredErrorMessage;
1829 QuestionRequired.ToolTip = _createUserWizard.QuestionRequiredErrorMessage;
1832 Label AnswerLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [8].Cells [0].Controls [0];
1833 AnswerLabel.Text = _createUserWizard.AnswerLabelText;
1835 RequiredFieldValidator AnswerRequired = (RequiredFieldValidator) FindControl ("AnswerRequired");
1836 AnswerRequired.ErrorMessage = _createUserWizard.AnswerRequiredErrorMessage;
1837 AnswerRequired.ToolTip = _createUserWizard.AnswerRequiredErrorMessage;
1840 ((Table) InnerCell.Controls [0]).Rows [7].Visible = false;
1841 ((Table) InnerCell.Controls [0]).Rows [8].Visible = false;
1845 if (_createUserWizard.AutoGeneratePassword) {
1846 ((Table) InnerCell.Controls [0]).Rows [9].Visible = false;
1849 CompareValidator PasswordCompare = (CompareValidator) FindControl ("PasswordCompare");
1850 PasswordCompare.ErrorMessage = _createUserWizard.ConfirmPasswordCompareErrorMessage;
1854 if (_createUserWizard.AutoGeneratePassword || String.IsNullOrEmpty (_createUserWizard.PasswordRegularExpression)) {
1855 ((Table) InnerCell.Controls [0]).Rows [10].Visible = false;
1858 RegularExpressionValidator PasswordRegEx = (RegularExpressionValidator) FindControl ("PasswordRegEx");
1859 PasswordRegEx.ValidationExpression = _createUserWizard.PasswordRegularExpression;
1860 PasswordRegEx.ErrorMessage = _createUserWizard.PasswordRegularExpressionErrorMessage;
1864 if (!_createUserWizard.RequireEmail || String.IsNullOrEmpty (_createUserWizard.EmailRegularExpression)) {
1865 ((Table) InnerCell.Controls [0]).Rows [11].Visible = false;
1868 RegularExpressionValidator EmailRegEx = (RegularExpressionValidator) FindControl ("EmailRegEx");
1869 EmailRegEx.ErrorMessage = _createUserWizard.EmailRegularExpressionErrorMessage;
1870 EmailRegEx.ValidationExpression = _createUserWizard.EmailRegularExpression;
1874 if (String.IsNullOrEmpty (ErrorMessageLabel.Text)) {
1875 ((Table) InnerCell.Controls [0]).Rows [12].Visible = false;
1880 Image img = (Image) ((Table) InnerCell.Controls [0]).Rows [13].Cells [0].Controls [0];
1881 if (String.IsNullOrEmpty (_createUserWizard.HelpPageIconUrl)) {
1882 img.Visible = false;
1885 img.ImageUrl = _createUserWizard.HelpPageIconUrl;
1886 img.AlternateText = _createUserWizard.HelpPageText;
1890 HyperLink link = (HyperLink) ((Table) InnerCell.Controls [0]).Rows [13].Cells [0].Controls [1];
1891 if (String.IsNullOrEmpty (_createUserWizard.HelpPageText)) {
1892 link.Visible = false;
1895 link.Text = _createUserWizard.HelpPageText;
1896 link.NavigateUrl = _createUserWizard.HelpPageUrl;
1899 ((Table) InnerCell.Controls [0]).Rows [13].Visible = img.Visible || link.Visible;
1903 public void EnsureValidatorsState ()
1905 if (!IsDefaultTemplate)
1908 ((RequiredFieldValidator) FindControl ("PasswordRequired")).Enabled = !_createUserWizard.AutoGeneratePassword;
1909 ((RequiredFieldValidator) FindControl ("ConfirmPasswordRequired")).Enabled = !_createUserWizard.AutoGeneratePassword;
1910 ((CompareValidator) FindControl ("PasswordCompare")).Enabled = !_createUserWizard.AutoGeneratePassword;
1911 RegularExpressionValidator PasswordRegEx = (RegularExpressionValidator) FindControl ("PasswordRegEx");
1912 PasswordRegEx.Enabled = !_createUserWizard.AutoGeneratePassword && !String.IsNullOrEmpty (_createUserWizard.PasswordRegularExpression);
1913 PasswordRegEx.ValidationExpression = _createUserWizard.PasswordRegularExpression;
1915 ((RequiredFieldValidator) FindControl ("EmailRequired")).Enabled = _createUserWizard.RequireEmail;
1916 RegularExpressionValidator EmailRegEx = (RegularExpressionValidator) FindControl ("EmailRegEx");
1917 EmailRegEx.Enabled = _createUserWizard.RequireEmail && !String.IsNullOrEmpty (_createUserWizard.EmailRegularExpression);
1918 EmailRegEx.ValidationExpression = _createUserWizard.EmailRegularExpression;
1920 ((RequiredFieldValidator) FindControl ("QuestionRequired")).Enabled = _createUserWizard.QuestionAndAnswerRequired;
1921 ((RequiredFieldValidator) FindControl ("AnswerRequired")).Enabled = _createUserWizard.QuestionAndAnswerRequired;
1925 sealed class CreateUserStepTemplate : ITemplate
1927 readonly CreateUserWizard _createUserWizard;
1929 public CreateUserStepTemplate (CreateUserWizard createUserWizard)
1931 _createUserWizard = createUserWizard;
1934 #region ITemplate Members
1936 TableRow CreateRow (Control c0, Control c1, Control c2, Style s0, Style s1) {
1937 TableRow row = new TableRow ();
1938 TableCell cell0 = new TableCell ();
1939 TableCell cell1 = new TableCell ();
1942 cell0.Controls.Add (c0);
1943 row.Controls.Add (cell0);
1945 if ((c1 != null) && (c2 != null)) {
1946 cell1.Controls.Add (c1);
1947 cell1.Controls.Add (c2);
1948 cell0.HorizontalAlign = HorizontalAlign.Right;
1951 _createUserWizard.RegisterApplyStyle (cell0, s0);
1953 _createUserWizard.RegisterApplyStyle (cell1, s1);
1955 row.Controls.Add (cell1);
1958 cell0.ColumnSpan = 2;
1959 cell0.HorizontalAlign = HorizontalAlign.Center;
1961 _createUserWizard.RegisterApplyStyle (cell0, s0);
1966 public void InstantiateIn (Control container) {
1967 Table table = new Table ();
1968 table.ControlStyle.Width = Unit.Percentage (100);
1969 table.ControlStyle.Height = Unit.Percentage (100);
1972 table.Controls.Add (CreateRow (null, null, null, _createUserWizard.TitleTextStyle, null));
1975 table.Controls.Add (CreateRow (null, null, null, _createUserWizard.InstructionTextStyle, null));
1978 TextBox UserName = new TextBox ();
1979 UserName.ID = "UserName";
1980 _createUserWizard.RegisterApplyStyle (UserName, _createUserWizard.TextBoxStyle);
1982 Label UserNameLabel = new Label ();
1983 UserNameLabel.AssociatedControlID = "UserName";
1985 RequiredFieldValidator UserNameRequired = new RequiredFieldValidator ();
1986 UserNameRequired.ID = "UserNameRequired";
1987 // alternatively we can create only required validators
1988 // and reinstantiate collection when relevant property changes
1989 UserNameRequired.EnableViewState = false;
1990 UserNameRequired.ControlToValidate = "UserName";
1991 UserNameRequired.Text = "*";
1992 UserNameRequired.ValidationGroup = _createUserWizard.ID;
1993 _createUserWizard.RegisterApplyStyle (UserNameRequired, _createUserWizard.ValidatorTextStyle);
1995 table.Controls.Add (CreateRow (UserNameLabel, UserName, UserNameRequired, _createUserWizard.LabelStyle, null));
1998 TextBox Password = new TextBox ();
1999 Password.ID = "Password";
2000 Password.TextMode = TextBoxMode.Password;
2001 _createUserWizard.RegisterApplyStyle (Password, _createUserWizard.TextBoxStyle);
2003 Label PasswordLabel = new Label ();
2004 PasswordLabel.AssociatedControlID = "Password";
2006 RequiredFieldValidator PasswordRequired = new RequiredFieldValidator ();
2007 PasswordRequired.ID = "PasswordRequired";
2008 PasswordRequired.EnableViewState = false;
2009 PasswordRequired.ControlToValidate = "Password";
2010 PasswordRequired.Text = "*";
2011 //PasswordRequired.EnableViewState = false;
2012 PasswordRequired.ValidationGroup = _createUserWizard.ID;
2013 _createUserWizard.RegisterApplyStyle (PasswordRequired, _createUserWizard.ValidatorTextStyle);
2015 table.Controls.Add (CreateRow (PasswordLabel, Password, PasswordRequired, _createUserWizard.LabelStyle, null));
2018 table.Controls.Add (CreateRow (new LiteralControl (""), new LiteralControl (""), new LiteralControl (""), null, _createUserWizard.PasswordHintStyle));
2021 TextBox ConfirmPassword = new TextBox ();
2022 ConfirmPassword.ID = "ConfirmPassword";
2023 ConfirmPassword.TextMode = TextBoxMode.Password;
2024 _createUserWizard.RegisterApplyStyle (ConfirmPassword, _createUserWizard.TextBoxStyle);
2026 Label ConfirmPasswordLabel = new Label ();
2027 ConfirmPasswordLabel.AssociatedControlID = "ConfirmPassword";
2029 RequiredFieldValidator ConfirmPasswordRequired = new RequiredFieldValidator ();
2030 ConfirmPasswordRequired.ID = "ConfirmPasswordRequired";
2031 ConfirmPasswordRequired.EnableViewState = false;
2032 ConfirmPasswordRequired.ControlToValidate = "ConfirmPassword";
2033 ConfirmPasswordRequired.Text = "*";
2034 ConfirmPasswordRequired.ValidationGroup = _createUserWizard.ID;
2035 _createUserWizard.RegisterApplyStyle (ConfirmPasswordRequired, _createUserWizard.ValidatorTextStyle);
2037 table.Controls.Add (CreateRow (ConfirmPasswordLabel, ConfirmPassword, ConfirmPasswordRequired, _createUserWizard.LabelStyle, null));
2040 TextBox Email = new TextBox ();
2042 _createUserWizard.RegisterApplyStyle (Email, _createUserWizard.TextBoxStyle);
2044 Label EmailLabel = new Label ();
2045 EmailLabel.AssociatedControlID = "Email";
2047 RequiredFieldValidator EmailRequired = new RequiredFieldValidator ();
2048 EmailRequired.ID = "EmailRequired";
2049 EmailRequired.EnableViewState = false;
2050 EmailRequired.ControlToValidate = "Email";
2051 EmailRequired.Text = "*";
2052 EmailRequired.ValidationGroup = _createUserWizard.ID;
2053 _createUserWizard.RegisterApplyStyle (EmailRequired, _createUserWizard.ValidatorTextStyle);
2055 table.Controls.Add (CreateRow (EmailLabel, Email, EmailRequired, _createUserWizard.LabelStyle, null));
2058 TextBox Question = new TextBox ();
2059 Question.ID = "Question";
2060 _createUserWizard.RegisterApplyStyle (Question, _createUserWizard.TextBoxStyle);
2062 Label QuestionLabel = new Label ();
2063 QuestionLabel.AssociatedControlID = "Question";
2065 RequiredFieldValidator QuestionRequired = new RequiredFieldValidator ();
2066 QuestionRequired.ID = "QuestionRequired";
2067 QuestionRequired.EnableViewState = false;
2068 QuestionRequired.ControlToValidate = "Question";
2069 QuestionRequired.Text = "*";
2070 QuestionRequired.ValidationGroup = _createUserWizard.ID;
2071 _createUserWizard.RegisterApplyStyle (QuestionRequired, _createUserWizard.ValidatorTextStyle);
2073 table.Controls.Add (CreateRow (QuestionLabel, Question, QuestionRequired, _createUserWizard.LabelStyle, null));
2076 TextBox Answer = new TextBox ();
2077 Answer.ID = "Answer";
2078 _createUserWizard.RegisterApplyStyle (Answer, _createUserWizard.TextBoxStyle);
2080 Label AnswerLabel = new Label ();
2081 AnswerLabel.AssociatedControlID = "Answer";
2083 RequiredFieldValidator AnswerRequired = new RequiredFieldValidator ();
2084 AnswerRequired.ID = "AnswerRequired";
2085 AnswerRequired.EnableViewState = false;
2086 AnswerRequired.ControlToValidate = "Answer";
2087 AnswerRequired.Text = "*";
2088 AnswerRequired.ValidationGroup = _createUserWizard.ID;
2089 _createUserWizard.RegisterApplyStyle (AnswerRequired, _createUserWizard.ValidatorTextStyle);
2091 table.Controls.Add (CreateRow (AnswerLabel, Answer, AnswerRequired, _createUserWizard.LabelStyle, null));
2094 CompareValidator PasswordCompare = new CompareValidator ();
2095 PasswordCompare.ID = "PasswordCompare";
2096 PasswordCompare.EnableViewState = false;
2097 PasswordCompare.ControlToCompare = "Password";
2098 PasswordCompare.ControlToValidate = "ConfirmPassword";
2099 PasswordCompare.Display = ValidatorDisplay.Static;
2100 PasswordCompare.ValidationGroup = _createUserWizard.ID;
2101 PasswordCompare.Display = ValidatorDisplay.Dynamic;
2102 _createUserWizard.RegisterApplyStyle (PasswordCompare, _createUserWizard.ValidatorTextStyle);
2104 table.Controls.Add (CreateRow (PasswordCompare, null, null, null, null));
2107 RegularExpressionValidator PasswordRegEx = new RegularExpressionValidator ();
2108 PasswordRegEx.ID = "PasswordRegEx";
2109 PasswordRegEx.EnableViewState = false;
2110 PasswordRegEx.ControlToValidate = "Password";
2111 PasswordRegEx.Display = ValidatorDisplay.Static;
2112 PasswordRegEx.ValidationGroup = _createUserWizard.ID;
2113 PasswordRegEx.Display = ValidatorDisplay.Dynamic;
2114 _createUserWizard.RegisterApplyStyle (PasswordRegEx, _createUserWizard.ValidatorTextStyle);
2116 table.Controls.Add (CreateRow (PasswordRegEx, null, null, null, null));
2119 RegularExpressionValidator EmailRegEx = new RegularExpressionValidator ();
2120 EmailRegEx.ID = "EmailRegEx";
2121 EmailRegEx.EnableViewState = false;
2122 EmailRegEx.ControlToValidate = "Email";
2123 EmailRegEx.Display = ValidatorDisplay.Static;
2124 EmailRegEx.ValidationGroup = _createUserWizard.ID;
2125 EmailRegEx.Display = ValidatorDisplay.Dynamic;
2126 _createUserWizard.RegisterApplyStyle (EmailRegEx, _createUserWizard.ValidatorTextStyle);
2128 table.Controls.Add (CreateRow (EmailRegEx, null, null, null, null));
2131 Label ErrorMessage = new Label ();
2132 ErrorMessage.ID = "ErrorMessage";
2133 ErrorMessage.EnableViewState = false;
2134 _createUserWizard.RegisterApplyStyle (ErrorMessage, _createUserWizard.ValidatorTextStyle);
2136 table.Controls.Add (CreateRow (ErrorMessage, null, null, null, null));
2139 TableRow row13 = CreateRow (new Image (), null, null, null, null);
2141 HyperLink HelpLink = new HyperLink ();
2142 HelpLink.ID = "HelpLink";
2143 _createUserWizard.RegisterApplyStyle (HelpLink, _createUserWizard.HyperLinkStyle);
2144 row13.Cells [0].Controls.Add (HelpLink);
2146 row13.Cells [0].HorizontalAlign = HorizontalAlign.Left;
2147 table.Controls.Add (row13);
2150 container.Controls.Add (table);
2156 sealed class CompleteStepContainer : DefaultContentContainer
2158 CreateUserWizard _createUserWizard;
2160 public CompleteStepContainer (CreateUserWizard createUserWizard)
2161 : base (createUserWizard)
2163 _createUserWizard = createUserWizard;
2166 protected override void UpdateState ()
2169 if (String.IsNullOrEmpty (_createUserWizard.CompleteStep.Title)) {
2170 ((Table) InnerCell.Controls [0]).Rows [0].Visible = false;
2173 ((Table) InnerCell.Controls [0]).Rows [0].Cells [0].Text = _createUserWizard.CompleteStep.Title;
2176 // CompleteSuccessText
2177 if (String.IsNullOrEmpty (_createUserWizard.CompleteSuccessText)) {
2178 ((Table) InnerCell.Controls [0]).Rows [1].Visible = false;
2181 ((Table) InnerCell.Controls [0]).Rows [1].Cells [0].Text = _createUserWizard.CompleteSuccessText;
2185 UpdateNavButtonState ("ContinueButton" + _createUserWizard.ContinueButtonType, _createUserWizard.ContinueButtonText, _createUserWizard.ContinueButtonImageUrl, _createUserWizard.ContinueButtonStyle);
2187 // EditProfileIconUrl
2188 Image img = (Image) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [0];
2189 if (String.IsNullOrEmpty (_createUserWizard.EditProfileIconUrl)) {
2190 img.Visible = false;
2193 img.ImageUrl = _createUserWizard.EditProfileIconUrl;
2194 img.AlternateText = _createUserWizard.EditProfileText;
2198 HyperLink link = (HyperLink) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [1];
2199 if (String.IsNullOrEmpty (_createUserWizard.EditProfileText)) {
2200 link.Visible = false;
2203 link.Text = _createUserWizard.EditProfileText;
2204 link.NavigateUrl = _createUserWizard.EditProfileUrl;
2207 ((Table) InnerCell.Controls [0]).Rows [3].Visible = img.Visible || link.Visible;
2210 void UpdateNavButtonState (string id, string text, string image, Style style)
2212 WebControl b = (WebControl) FindControl (id);
2213 foreach (Control c in b.Parent.Controls)
2216 ((IButtonControl) b).Text = text;
2217 ImageButton imgbtn = b as ImageButton;
2219 imgbtn.ImageUrl = image;
2221 b.ApplyStyle (style);
2225 sealed class CompleteStepTemplate : ITemplate
2227 readonly CreateUserWizard _createUserWizard;
2229 public CompleteStepTemplate (CreateUserWizard createUserWizard)
2231 _createUserWizard = createUserWizard;
2234 #region ITemplate Members
2236 public void InstantiateIn (Control container)
2238 Table table = new Table ();
2241 TableRow row0 = new TableRow ();
2242 TableCell cell00 = new TableCell ();
2244 cell00.HorizontalAlign = HorizontalAlign.Center;
2245 cell00.ColumnSpan = 2;
2246 _createUserWizard.RegisterApplyStyle (cell00, _createUserWizard.TitleTextStyle);
2247 row0.Cells.Add (cell00);
2250 TableRow row1 = new TableRow ();
2251 TableCell cell10 = new TableCell ();
2253 cell10.HorizontalAlign = HorizontalAlign.Center;
2254 _createUserWizard.RegisterApplyStyle (cell10, _createUserWizard.CompleteSuccessTextStyle);
2255 row1.Cells.Add (cell10);
2258 TableRow row2 = new TableRow ();
2259 TableCell cell20 = new TableCell ();
2261 cell20.HorizontalAlign = HorizontalAlign.Right;
2262 cell20.ColumnSpan = 2;
2263 row2.Cells.Add (cell20);
2265 Control[] b = _createUserWizard.CreateButtonSet ("ContinueButton", CreateUserWizard.ContinueButtonCommandName);
2266 for (int i = 0; i < b.Length; i++)
2267 cell20.Controls.Add (b [i]);
2270 TableRow row3 = new TableRow ();
2271 TableCell cell30 = new TableCell ();
2273 cell30.Controls.Add (new Image ());
2274 HyperLink link = new HyperLink ();
2275 link.ID = "EditProfileLink";
2276 _createUserWizard.RegisterApplyStyle (link, _createUserWizard.HyperLinkStyle);
2277 cell30.Controls.Add (link);
2278 row3.Cells.Add (cell30);
2281 table.Rows.Add (row0);
2282 table.Rows.Add (row1);
2283 table.Rows.Add (row2);
2284 table.Rows.Add (row3);
2286 container.Controls.Add (table);