a222c4cf1af49d2dbb12e5f625cb4a562ccffb62
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / CreateUserWizard.cs
1 //
2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
3 //
4 // Authors:
5 //      Vladimir Krasnov <vladimirk@mainsoft.com>
6 //
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:
14 //
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 //
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.
25 //
26
27 #if NET_2_0
28
29 using System;
30 using System.Web;
31 using System.Web.UI;
32 using System.Web.Security;
33 using System.Collections;
34 using System.ComponentModel;
35 using System.Text;
36
37 namespace System.Web.UI.WebControls
38 {
39         [BindableAttribute (false)]
40         public class CreateUserWizard : Wizard
41         {
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;
47
48                 private Style _textBoxStyle = null;
49                 private Style _validatorTextStyle = null;
50
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;
60
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 ();
67
68                 private CompleteWizardStep _completeWizardStep = null;
69                 private CreateUserWizardStep _createUserWizardStep = null;
70
71                 public CreateUserWizard ()
72                 {
73                 }
74
75                 #region Public Properties
76
77                 public override int ActiveStepIndex
78                 {
79                         get { return base.ActiveStepIndex; }
80                         set { base.ActiveStepIndex = value; }
81                 }
82
83                 [LocalizableAttribute (true)]
84                 [ThemeableAttribute (false)]
85                 public virtual string Answer
86                 {
87                         get
88                         {
89                                 object o = ViewState ["Answer"];
90                                 return (o == null) ? String.Empty : (string) o;
91                         }
92                         set
93                         {
94                                 if (value == null)
95                                         ViewState.Remove ("Answer");
96                                 else
97                                         ViewState ["Answer"] = value;
98                         }
99                 }
100
101                 [LocalizableAttribute (true)]
102                 public virtual string AnswerLabelText
103                 {
104                         get
105                         {
106                                 object o = ViewState ["AnswerLabelText"];
107                                 return (o == null) ? Locale.GetText ("Security Answer:") : (string) o;
108                         }
109                         set
110                         {
111                                 if (value == null)
112                                         ViewState.Remove ("AnswerLabelText");
113                                 else
114                                         ViewState ["AnswerLabelText"] = value;
115                         }
116                 }
117
118                 [LocalizableAttribute (true)]
119                 public virtual string AnswerRequiredErrorMessage
120                 {
121                         get
122                         {
123                                 object o = ViewState ["AnswerRequiredErrorMessage"];
124                                 return (o == null) ? Locale.GetText ("Security answer is required.") : (string) o;
125                         }
126                         set
127                         {
128                                 if (value == null)
129                                         ViewState.Remove ("AnswerRequiredErrorMessage");
130                                 else
131                                         ViewState ["AnswerRequiredErrorMessage"] = value;
132                         }
133                 }
134
135                 [ThemeableAttribute (false)]
136                 public virtual bool AutoGeneratePassword
137                 {
138                         get
139                         {
140                                 object o = ViewState ["AutoGeneratePassword"];
141                                 return (o == null) ? false : (bool) o;
142                         }
143                         set
144                         {
145                                 ViewState ["AutoGeneratePassword"] = value;
146                         }
147                 }
148
149                 public CompleteWizardStep CompleteStep
150                 {
151                         get
152                         {
153                                 if (_completeWizardStep == null) {
154                                         for (int i = 0; i < WizardSteps.Count; i++)
155                                                 if (WizardSteps [i] is CompleteWizardStep) {
156                                                         _completeWizardStep = (CompleteWizardStep) WizardSteps [i];
157
158                                                         if (_completeWizardStep.Wizard == null)
159                                                                 _completeWizardStep.SetWizard (this);
160                                                 }
161                                 }
162                                 return _completeWizardStep;
163                         }
164                 }
165
166                 [LocalizableAttribute (true)]
167                 public virtual string CompleteSuccessText
168                 {
169                         get
170                         {
171                                 object o = ViewState ["CompleteSuccessText"];
172                                 return (o == null) ? Locale.GetText ("Your account has been successfully created.") : (string) o;
173                         }
174                         set
175                         {
176                                 if (value == null)
177                                         ViewState.Remove ("CompleteSuccessText");
178                                 else
179                                         ViewState ["CompleteSuccessText"] = value;
180                         }
181                 }
182
183                 public TableItemStyle CompleteSuccessTextStyle
184                 {
185                         get
186                         {
187                                 if (_completeSuccessTextStyle == null) {
188                                         _completeSuccessTextStyle = new TableItemStyle ();
189                                         if (IsTrackingViewState)
190                                                 ((IStateManager) _completeSuccessTextStyle).TrackViewState ();
191                                 }
192                                 return _completeSuccessTextStyle;
193                         }
194                 }
195
196                 public virtual string ConfirmPassword
197                 {
198                         get { return _confirmPassword; }
199                 }
200
201                 [LocalizableAttribute (true)]
202                 public virtual string ConfirmPasswordCompareErrorMessage
203                 {
204                         get
205                         {
206                                 object o = ViewState ["ConfirmPasswordCompareErrorMessage"];
207                                 return (o == null) ? Locale.GetText ("The Password and Confirmation Password must match.") : (string) o;
208                         }
209                         set
210                         {
211                                 if (value == null)
212                                         ViewState.Remove ("ConfirmPasswordCompareErrorMessage");
213                                 else
214                                         ViewState ["ConfirmPasswordCompareErrorMessage"] = value;
215                         }
216                 }
217
218                 [LocalizableAttribute (true)]
219                 public virtual string ConfirmPasswordLabelText
220                 {
221                         get
222                         {
223                                 object o = ViewState ["ConfirmPasswordLabelText"];
224                                 return (o == null) ? Locale.GetText ("Confirm Password:") : (string) o;
225                         }
226                         set
227                         {
228                                 if (value == null)
229                                         ViewState.Remove ("ConfirmPasswordLabelText");
230                                 else
231                                         ViewState ["ConfirmPasswordLabelText"] = value;
232                         }
233                 }
234
235                 [LocalizableAttribute (true)]
236                 public virtual string ConfirmPasswordRequiredErrorMessage
237                 {
238                         get
239                         {
240                                 object o = ViewState ["ConfirmPasswordRequiredErrorMessage"];
241                                 return (o == null) ? Locale.GetText ("Confirm Password is required.") : (string) o;
242                         }
243                         set
244                         {
245                                 if (value == null)
246                                         ViewState.Remove ("ConfirmPasswordRequiredErrorMessage");
247                                 else
248                                         ViewState ["ConfirmPasswordRequiredErrorMessage"] = value;
249                         }
250                 }
251
252                 public virtual string ContinueButtonImageUrl
253                 {
254                         get { return ViewState.GetString ("ContinueButtonImageUrl", String.Empty); }
255                         set { ViewState ["ContinueButtonImageUrl"] = value; }
256                 }
257
258                 public Style ContinueButtonStyle
259                 {
260                         get {
261                                 if (_continueButtonStyle == null) {
262                                         _continueButtonStyle = new Style ();
263                                         if (IsTrackingViewState)
264                                                 ((IStateManager) _continueButtonStyle).TrackViewState ();
265                                 }
266                                 return _continueButtonStyle;
267                         }
268                 }
269
270                 [LocalizableAttribute (true)]
271                 public virtual string ContinueButtonText
272                 {
273                         get { return ViewState.GetString ("ContinueButtonText", "Continue"); }
274                         set { ViewState ["ContinueButtonText"] = value; }
275                 }
276
277                 public virtual ButtonType ContinueButtonType
278                 {
279                         get {
280                                 object v = ViewState ["ContinueButtonType"];
281                                 return v != null ? (ButtonType) v : ButtonType.Button;
282                         }
283                         set {
284                                 ViewState ["ContinueButtonType"] = value;
285                         }
286                 }
287
288                 [ThemeableAttribute (false)]
289                 public virtual string ContinueDestinationPageUrl
290                 {
291                         get
292                         {
293                                 object o = ViewState ["ContinueDestinationPageUrl"];
294                                 return (o == null) ? "" : (string) o;
295                         }
296                         set
297                         {
298                                 if (value == null)
299                                         ViewState.Remove ("ContinueDestinationPageUrl");
300                                 else
301                                         ViewState ["ContinueDestinationPageUrl"] = value;
302                         }
303                 }
304
305                 public virtual string CreateUserButtonImageUrl
306                 {
307                         get { return ViewState.GetString ("CreateUserButtonImageUrl", String.Empty); }
308                         set { ViewState ["CreateUserButtonImageUrl"] = value; }
309                 }
310
311                 public Style CreateUserButtonStyle
312                 {
313                         get {
314                                 if (_createUserButtonStyle == null) {
315                                         _createUserButtonStyle = new Style ();
316                                         if (IsTrackingViewState)
317                                                 ((IStateManager) _createUserButtonStyle).TrackViewState ();
318                                 }
319                                 return _createUserButtonStyle;
320                         }
321                 }
322
323                 [LocalizableAttribute (true)]
324                 public virtual string CreateUserButtonText
325                 {
326                         get { return ViewState.GetString ("CreateUserButtonText", "Create User"); }
327                         set { ViewState ["CreateUserButtonText"] = value; }
328                 }
329
330                 public virtual ButtonType CreateUserButtonType
331                 {
332                         get {
333                                 object v = ViewState ["CreateUserButtonType"];
334                                 return v != null ? (ButtonType) v : ButtonType.Button;
335                         }
336                         set {
337                                 ViewState ["CreateUserButtonType"] = value;
338                         }
339                 }
340
341                 public CreateUserWizardStep CreateUserStep
342                 {
343                         get
344                         {
345                                 if (_createUserWizardStep == null) {
346                                         for (int i = 0; i < WizardSteps.Count; i++)
347                                                 if (WizardSteps [i] is CreateUserWizardStep) {
348                                                         _createUserWizardStep = (CreateUserWizardStep) WizardSteps [i];
349
350                                                         if (_createUserWizardStep.Wizard == null)
351                                                                 _createUserWizardStep.SetWizard (this);
352                                                 }
353                                 }
354                                 return _createUserWizardStep;
355                         }
356                 }
357
358                 [ThemeableAttribute (false)]
359                 public virtual bool DisableCreatedUser
360                 {
361                         get
362                         {
363                                 object o = ViewState ["DisableCreatedUser"];
364                                 return (o == null) ? false : (bool) o;
365                         }
366                         set
367                         {
368                                 ViewState ["DisableCreatedUser"] = value;
369                         }
370                 }
371
372                 public override bool DisplaySideBar
373                 {
374                         get {
375                                 return ViewState.GetBool ("DisplaySideBar", false);
376                         }
377                         set {
378                                 ViewState ["DisplaySideBar"] = value;
379                                 ChildControlsCreated = false;
380                         }
381                 }
382
383                 [LocalizableAttribute (true)]
384                 public virtual string DuplicateEmailErrorMessage
385                 {
386                         get
387                         {
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;
390                         }
391                         set
392                         {
393                                 if (value == null)
394                                         ViewState.Remove ("DuplicateEmailErrorMessage");
395                                 else
396                                         ViewState ["DuplicateEmailErrorMessage"] = value;
397                         }
398                 }
399
400                 [LocalizableAttribute (true)]
401                 public virtual string DuplicateUserNameErrorMessage
402                 {
403                         get
404                         {
405                                 object o = ViewState ["DuplicateUserNameErrorMessage"];
406                                 return (o == null) ? Locale.GetText ("Please enter a different user name.") : (string) o;
407                         }
408                         set
409                         {
410                                 if (value == null)
411                                         ViewState.Remove ("DuplicateUserNameErrorMessage");
412                                 else
413                                         ViewState ["DuplicateUserNameErrorMessage"] = value;
414                         }
415                 }
416
417                 public virtual string EditProfileIconUrl
418                 {
419                         get
420                         {
421                                 object o = ViewState ["EditProfileIconUrl"];
422                                 return (o == null) ? "" : (string) o;
423                         }
424                         set
425                         {
426                                 if (value == null)
427                                         ViewState.Remove ("EditProfileIconUrl");
428                                 else
429                                         ViewState ["EditProfileIconUrl"] = value;
430                         }
431                 }
432
433                 [LocalizableAttribute (true)]
434                 public virtual string EditProfileText
435                 {
436                         get
437                         {
438                                 object o = ViewState ["EditProfileText"];
439                                 return (o == null) ? "" : (string) o;
440                         }
441                         set
442                         {
443                                 if (value == null)
444                                         ViewState.Remove ("EditProfileText");
445                                 else
446                                         ViewState ["EditProfileText"] = value;
447                         }
448                 }
449
450                 public virtual string EditProfileUrl
451                 {
452                         get
453                         {
454                                 object o = ViewState ["EditProfileUrl"];
455                                 return (o == null) ? "" : (string) o;
456                         }
457                         set
458                         {
459                                 if (value == null)
460                                         ViewState.Remove ("EditProfileUrl");
461                                 else
462                                         ViewState ["EditProfileUrl"] = value;
463                         }
464                 }
465
466                 public virtual string Email
467                 {
468                         get
469                         {
470                                 object o = ViewState ["Email"];
471                                 return (o == null) ? String.Empty : (string) o;
472                         }
473                         set
474                         {
475                                 if (value == null)
476                                         ViewState.Remove ("Email");
477                                 else
478                                         ViewState ["Email"] = value;
479                         }
480                 }
481
482                 [LocalizableAttribute (true)]
483                 public virtual string EmailLabelText
484                 {
485                         get
486                         {
487                                 object o = ViewState ["EmailLabelText"];
488                                 return (o == null) ? Locale.GetText ("E-mail:") : (string) o;
489                         }
490                         set
491                         {
492                                 if (value == null)
493                                         ViewState.Remove ("EmailLabelText");
494                                 else
495                                         ViewState ["EmailLabelText"] = value;
496                         }
497                 }
498
499                 public virtual string EmailRegularExpression
500                 {
501                         get
502                         {
503                                 object o = ViewState ["EmailRegularExpression"];
504                                 return (o == null) ? "" : (string) o;
505                         }
506                         set
507                         {
508                                 if (value == null)
509                                         ViewState.Remove ("EmailRegularExpression");
510                                 else
511                                         ViewState ["EmailRegularExpression"] = value;
512                         }
513                 }
514
515                 public virtual string EmailRegularExpressionErrorMessage
516                 {
517                         get
518                         {
519                                 object o = ViewState ["EmailRegularExpressionErrorMessage"];
520                                 return (o == null) ? Locale.GetText ("Please enter a different e-mail.") : (string) o;
521                         }
522                         set
523                         {
524                                 if (value == null)
525                                         ViewState.Remove ("EmailRegularExpressionErrorMessage");
526                                 else
527                                         ViewState ["EmailRegularExpressionErrorMessage"] = value;
528                         }
529                 }
530
531                 [LocalizableAttribute (true)]
532                 public virtual string EmailRequiredErrorMessage
533                 {
534                         get
535                         {
536                                 object o = ViewState ["EmailRequiredErrorMessage"];
537                                 return (o == null) ? Locale.GetText ("E-mail is required.") : (string) o;
538                         }
539                         set
540                         {
541                                 if (value == null)
542                                         ViewState.Remove ("EmailRequiredErrorMessage");
543                                 else
544                                         ViewState ["EmailRequiredErrorMessage"] = value;
545                         }
546                 }
547
548                 public TableItemStyle ErrorMessageStyle
549                 {
550                         get
551                         {
552                                 if (_errorMessageStyle == null) {
553                                         _errorMessageStyle = new TableItemStyle ();
554                                         if (IsTrackingViewState)
555                                                 ((IStateManager) _errorMessageStyle).TrackViewState ();
556                                 }
557                                 return _errorMessageStyle;
558                         }
559                 }
560
561                 public virtual string HelpPageIconUrl
562                 {
563                         get
564                         {
565                                 object o = ViewState ["HelpPageIconUrl"];
566                                 return (o == null) ? "" : (string) o;
567                         }
568                         set
569                         {
570                                 if (value == null)
571                                         ViewState.Remove ("HelpPageIconUrl");
572                                 else
573                                         ViewState ["HelpPageIconUrl"] = value;
574                         }
575                 }
576
577                 [LocalizableAttribute (true)]
578                 public virtual string HelpPageText
579                 {
580                         get
581                         {
582                                 object o = ViewState ["HelpPageText"];
583                                 return (o == null) ? "" : (string) o;
584                         }
585                         set
586                         {
587                                 if (value == null)
588                                         ViewState.Remove ("HelpPageText");
589                                 else
590                                         ViewState ["HelpPageText"] = value;
591                         }
592                 }
593
594                 public virtual string HelpPageUrl
595                 {
596                         get
597                         {
598                                 object o = ViewState ["HelpPageUrl"];
599                                 return (o == null) ? "" : (string) o;
600                         }
601                         set
602                         {
603                                 if (value == null)
604                                         ViewState.Remove ("HelpPageUrl");
605                                 else
606                                         ViewState ["HelpPageUrl"] = value;
607                         }
608                 }
609
610                 public TableItemStyle HyperLinkStyle
611                 {
612                         get
613                         {
614                                 if (_hyperLinkStyle == null) {
615                                         _hyperLinkStyle = new TableItemStyle ();
616                                         if (IsTrackingViewState)
617                                                 ((IStateManager) _hyperLinkStyle).TrackViewState ();
618                                 }
619                                 return _hyperLinkStyle;
620                         }
621                 }
622
623                 [LocalizableAttribute (true)]
624                 public virtual string InstructionText
625                 {
626                         get
627                         {
628                                 object o = ViewState ["InstructionText"];
629                                 return (o == null) ? "" : (string) o;
630                         }
631                         set
632                         {
633                                 if (value == null)
634                                         ViewState.Remove ("InstructionText");
635                                 else
636                                         ViewState ["InstructionText"] = value;
637                         }
638                 }
639
640                 public TableItemStyle InstructionTextStyle
641                 {
642                         get
643                         {
644                                 if (_instructionTextStyle == null) {
645                                         _instructionTextStyle = new TableItemStyle ();
646                                         if (IsTrackingViewState)
647                                                 ((IStateManager) _instructionTextStyle).TrackViewState ();
648                                 }
649                                 return _instructionTextStyle;
650                         }
651                 }
652
653                 [LocalizableAttribute (true)]
654                 public virtual string InvalidAnswerErrorMessage
655                 {
656                         get
657                         {
658                                 object o = ViewState ["InvalidAnswerErrorMessage"];
659                                 return (o == null) ? Locale.GetText ("Please enter a different security answer.") : (string) o;
660                         }
661                         set
662                         {
663                                 if (value == null)
664                                         ViewState.Remove ("InvalidAnswerErrorMessage");
665                                 else
666                                         ViewState ["InvalidAnswerErrorMessage"] = value;
667                         }
668                 }
669
670                 [LocalizableAttribute (true)]
671                 public virtual string InvalidEmailErrorMessage
672                 {
673                         get
674                         {
675                                 object o = ViewState ["InvalidEmailErrorMessage"];
676                                 return (o == null) ? Locale.GetText ("Please enter a valid e-mail address.") : (string) o;
677                         }
678                         set
679                         {
680                                 if (value == null)
681                                         ViewState.Remove ("InvalidEmailErrorMessage");
682                                 else
683                                         ViewState ["InvalidEmailErrorMessage"] = value;
684                         }
685                 }
686
687                 [MonoTODO ("take the values from membership provider")]
688                 [LocalizableAttribute (true)]
689                 public virtual string InvalidPasswordErrorMessage
690                 {
691                         get
692                         {
693                                 object o = ViewState ["InvalidPasswordErrorMessage"];
694                                 return (o == null) ? Locale.GetText ("Password length minimum: {0}. Non-alphanumeric characters required: {1}.") : (string) o;
695                         }
696                         set
697                         {
698                                 if (value == null)
699                                         ViewState.Remove ("InvalidPasswordErrorMessage");
700                                 else
701                                         ViewState ["InvalidPasswordErrorMessage"] = value;
702                         }
703                 }
704
705                 [LocalizableAttribute (true)]
706                 public virtual string InvalidQuestionErrorMessage
707                 {
708                         get
709                         {
710                                 object o = ViewState ["InvalidQuestionErrorMessage"];
711                                 return (o == null) ? Locale.GetText ("Please enter a different security question.") : (string) o;
712                         }
713                         set
714                         {
715                                 if (value == null)
716                                         ViewState.Remove ("InvalidQuestionErrorMessage");
717                                 else
718                                         ViewState ["InvalidQuestionErrorMessage"] = value;
719                         }
720                 }
721
722                 public TableItemStyle LabelStyle
723                 {
724                         get
725                         {
726                                 if (_labelStyle == null) {
727                                         _labelStyle = new TableItemStyle ();
728                                         if (IsTrackingViewState)
729                                                 ((IStateManager) _labelStyle).TrackViewState ();
730                                 }
731                                 return _labelStyle;
732                         }
733                 }
734
735                 [ThemeableAttribute (false)]
736                 public virtual bool LoginCreatedUser
737                 {
738                         get
739                         {
740                                 object o = ViewState ["LoginCreatedUser"];
741                                 return (o == null) ? true : (bool) o;
742                         }
743                         set
744                         {
745                                 ViewState ["LoginCreatedUser"] = value;
746                         }
747                 }
748
749                 //[MonoTODO ("Sending mail functionality is not implemented")]
750                 //[ThemeableAttribute (false)]
751                 //public MailDefinition MailDefinition
752                 //{
753                 //      get { throw new NotImplementedException (); }
754                 //}
755
756                 [ThemeableAttribute (false)]
757                 public virtual string MembershipProvider
758                 {
759                         get
760                         {
761                                 object o = ViewState ["MembershipProvider"];
762                                 return (o == null) ? "" : (string) o;
763                         }
764                         set
765                         {
766                                 if (value == null)
767                                         ViewState.Remove ("MembershipProvider");
768                                 else
769                                         ViewState ["MembershipProvider"] = value;
770
771                                 _provider = null;
772                         }
773                 }
774
775                 internal virtual MembershipProvider MembershipProviderInternal
776                 {
777                         get
778                         {
779                                 if (_provider == null)
780                                         InitMemberShipProvider ();
781
782                                 return _provider;
783                         }
784                 }
785
786                 public virtual string Password
787                 {
788                         get { return _password; }
789                 }
790
791                 public TableItemStyle PasswordHintStyle
792                 {
793                         get
794                         {
795                                 if (_passwordHintStyle == null) {
796                                         _passwordHintStyle = new TableItemStyle ();
797                                         if (IsTrackingViewState)
798                                                 ((IStateManager) _passwordHintStyle).TrackViewState ();
799                                 }
800                                 return _passwordHintStyle;
801                         }
802                 }
803
804                 [LocalizableAttribute (true)]
805                 public virtual string PasswordHintText
806                 {
807                         get
808                         {
809                                 object o = ViewState ["PasswordHintText"];
810                                 return (o == null) ? "" : (string) o;
811                         }
812                         set
813                         {
814                                 if (value == null)
815                                         ViewState.Remove ("PasswordHintText");
816                                 else
817                                         ViewState ["PasswordHintText"] = value;
818                         }
819                 }
820
821                 [LocalizableAttribute (true)]
822                 public virtual string PasswordLabelText
823                 {
824                         get
825                         {
826                                 object o = ViewState ["PasswordLabelText"];
827                                 return (o == null) ? Locale.GetText ("Password:") : (string) o;
828                         }
829                         set
830                         {
831                                 if (value == null)
832                                         ViewState.Remove ("PasswordLabelText");
833                                 else
834                                         ViewState ["PasswordLabelText"] = value;
835                         }
836                 }
837
838                 public virtual string PasswordRegularExpression
839                 {
840                         get
841                         {
842                                 object o = ViewState ["PasswordRegularExpression"];
843                                 return (o == null) ? "" : (string) o;
844                         }
845                         set
846                         {
847                                 if (value == null)
848                                         ViewState.Remove ("PasswordRegularExpression");
849                                 else
850                                         ViewState ["PasswordRegularExpression"] = value;
851                         }
852                 }
853
854                 public virtual string PasswordRegularExpressionErrorMessage
855                 {
856                         get
857                         {
858                                 object o = ViewState ["PasswordRegularExpressionErrorMessage"];
859                                 return (o == null) ? Locale.GetText ("Please enter a different password.") : (string) o;
860                         }
861                         set
862                         {
863                                 if (value == null)
864                                         ViewState.Remove ("PasswordRegularExpressionErrorMessage");
865                                 else
866                                         ViewState ["PasswordRegularExpressionErrorMessage"] = value;
867                         }
868                 }
869
870                 [LocalizableAttribute (true)]
871                 public virtual string PasswordRequiredErrorMessage
872                 {
873                         get
874                         {
875                                 object o = ViewState ["PasswordRequiredErrorMessage"];
876                                 return (o == null) ? Locale.GetText ("Password is required.") : (string) o;
877                         }
878                         set
879                         {
880                                 if (value == null)
881                                         ViewState.Remove ("PasswordRequiredErrorMessage");
882                                 else
883                                         ViewState ["PasswordRequiredErrorMessage"] = value;
884                         }
885                 }
886
887                 [LocalizableAttribute (true)]
888                 [ThemeableAttribute (false)]
889                 public virtual string Question
890                 {
891                         get
892                         {
893                                 object o = ViewState ["Question"];
894                                 return (o == null) ? String.Empty : (string) o;
895                         }
896                         set
897                         {
898                                 if (value == null)
899                                         ViewState.Remove ("Question");
900                                 else
901                                         ViewState ["Question"] = value;
902                         }
903                 }
904
905                 [LocalizableAttribute (true)]
906                 public virtual string QuestionLabelText
907                 {
908                         get
909                         {
910                                 object o = ViewState ["QuestionLabelText"];
911                                 return (o == null) ? Locale.GetText ("Security Question:") : (string) o;
912                         }
913                         set
914                         {
915                                 if (value == null)
916                                         ViewState.Remove ("QuestionLabelText");
917                                 else
918                                         ViewState ["QuestionLabelText"] = value;
919                         }
920                 }
921
922                 [LocalizableAttribute (true)]
923                 public virtual string QuestionRequiredErrorMessage
924                 {
925                         get
926                         {
927                                 object o = ViewState ["QuestionRequiredErrorMessage"];
928                                 return (o == null) ? Locale.GetText ("Security question is required.") : (string) o;
929                         }
930                         set
931                         {
932                                 if (value == null)
933                                         ViewState.Remove ("QuestionRequiredErrorMessage");
934                                 else
935                                         ViewState ["QuestionRequiredErrorMessage"] = value;
936                         }
937                 }
938
939                 [ThemeableAttribute (false)]
940                 public virtual bool RequireEmail
941                 {
942                         get
943                         {
944                                 object o = ViewState ["RequireEmail"];
945                                 return (o == null) ? true : (bool) o;
946                         }
947                         set
948                         {
949                                 ViewState ["RequireEmail"] = value;
950                         }
951                 }
952
953                 [MonoTODO ("doesnt work")]
954                 public override string SkipLinkText
955                 {
956                         get
957                         {
958                                 object o = ViewState ["SkipLinkText"];
959                                 return (o == null) ? "" : (string) o;
960                         }
961                         set
962                         {
963                                 if (value == null)
964                                         ViewState.Remove ("SkipLinkText");
965                                 else
966                                         ViewState ["SkipLinkText"] = value;
967                         }
968                 }
969
970                 public Style TextBoxStyle
971                 {
972                         get
973                         {
974                                 if (_textBoxStyle == null) {
975                                         _textBoxStyle = new Style ();
976                                         if (IsTrackingViewState)
977                                                 ((IStateManager) _textBoxStyle).TrackViewState ();
978                                 }
979                                 return _textBoxStyle;
980                         }
981                 }
982
983                 public TableItemStyle TitleTextStyle
984                 {
985                         get
986                         {
987                                 if (_titleTextStyle == null) {
988                                         _titleTextStyle = new TableItemStyle ();
989                                         if (IsTrackingViewState)
990                                                 ((IStateManager) _titleTextStyle).TrackViewState ();
991                                 }
992                                 return _titleTextStyle;
993                         }
994                 }
995
996                 [LocalizableAttribute (true)]
997                 public virtual string UnknownErrorMessage
998                 {
999                         get
1000                         {
1001                                 object o = ViewState ["UnknownErrorMessage"];
1002                                 return (o == null) ? Locale.GetText ("Your account was not created. Please try again.") : (string) o;
1003                         }
1004                         set
1005                         {
1006                                 if (value == null)
1007                                         ViewState.Remove ("UnknownErrorMessage");
1008                                 else
1009                                         ViewState ["UnknownErrorMessage"] = value;
1010                         }
1011                 }
1012
1013                 public virtual string UserName
1014                 {
1015                         get
1016                         {
1017                                 object o = ViewState ["UserName"];
1018                                 return (o == null) ? String.Empty : (string) o;
1019                         }
1020                         set
1021                         {
1022                                 if (value == null)
1023                                         ViewState.Remove ("UserName");
1024                                 else
1025                                         ViewState ["UserName"] = value;
1026                         }
1027                 }
1028
1029                 [LocalizableAttribute (true)]
1030                 public virtual string UserNameLabelText
1031                 {
1032                         get
1033                         {
1034                                 object o = ViewState ["UserNameLabelText"];
1035                                 return (o == null) ? Locale.GetText ("User Name:") : (string) o;
1036                         }
1037                         set
1038                         {
1039                                 if (value == null)
1040                                         ViewState.Remove ("UserNameLabelText");
1041                                 else
1042                                         ViewState ["UserNameLabelText"] = value;
1043                         }
1044                 }
1045
1046                 [LocalizableAttribute (true)]
1047                 public virtual string UserNameRequiredErrorMessage
1048                 {
1049                         get
1050                         {
1051                                 object o = ViewState ["UserNameRequiredErrorMessage"];
1052                                 return (o == null) ? Locale.GetText ("User Name is required.") : (string) o;
1053                         }
1054                         set
1055                         {
1056                                 if (value == null)
1057                                         ViewState.Remove ("UserNameRequiredErrorMessage");
1058                                 else
1059                                         ViewState ["UserNameRequiredErrorMessage"] = value;
1060                         }
1061                 }
1062
1063                 public Style ValidatorTextStyle
1064                 {
1065                         get
1066                         {
1067                                 if (_validatorTextStyle == null) {
1068                                         _validatorTextStyle = new Style ();
1069                                         if (IsTrackingViewState)
1070                                                 ((IStateManager) _validatorTextStyle).TrackViewState ();
1071                                 }
1072                                 return _validatorTextStyle;
1073                         }
1074                 }
1075
1076                 [ThemeableAttribute (false)]
1077                 public override WizardStepCollection WizardSteps
1078                 {
1079                         get { return base.WizardSteps; }
1080                 }
1081
1082                 #endregion
1083
1084                 #region Protected Properties
1085
1086                 protected internal bool QuestionAndAnswerRequired
1087                 {
1088                         get { return MembershipProviderInternal.RequiresQuestionAndAnswer; }
1089                 }
1090
1091                 public event EventHandler ContinueButtonClick
1092                 {
1093                         add { Events.AddHandler (ContinueButtonClickEvent, value); }
1094                         remove { Events.RemoveHandler (ContinueButtonClickEvent, value); }
1095                 }
1096
1097                 public event EventHandler CreatedUser
1098                 {
1099                         add { Events.AddHandler (CreatedUserEvent, value); }
1100                         remove { Events.RemoveHandler (CreatedUserEvent, value); }
1101                 }
1102
1103                 public event CreateUserErrorEventHandler CreateUserError
1104                 {
1105                         add { Events.AddHandler (CreateUserErrorEvent, value); }
1106                         remove { Events.RemoveHandler (CreateUserErrorEvent, value); }
1107                 }
1108
1109                 public event LoginCancelEventHandler CreatingUser
1110                 {
1111                         add { Events.AddHandler (CreatingUserEvent, value); }
1112                         remove { Events.RemoveHandler (CreatingUserEvent, value); }
1113                 }
1114
1115                 public event MailMessageEventHandler SendingMail
1116                 {
1117                         add { Events.AddHandler (SendingMailEvent, value); }
1118                         remove { Events.RemoveHandler (SendingMailEvent, value); }
1119                 }
1120
1121                 public event SendMailErrorEventHandler SendMailError
1122                 {
1123                         add { Events.AddHandler (SendMailErrorEvent, value); }
1124                         remove { Events.RemoveHandler (SendMailErrorEvent, value); }
1125                 }
1126
1127
1128                 #endregion
1129
1130                 #region Internal Properties
1131
1132                 internal override void InstantiateTemplateStep (TemplatedWizardStep step)
1133                 {
1134                         if (step is CreateUserWizardStep) {
1135                                 InstantiateCreateUserWizardStep ((CreateUserWizardStep) step);
1136                         }
1137                         else if (step is CompleteWizardStep) {
1138                                 InstantiateCompleteWizardStep ((CompleteWizardStep) step);
1139                         }
1140                         else {
1141                                 base.InstantiateTemplateStep (step);
1142                         }
1143                 }
1144
1145                 private void InstantiateCompleteWizardStep (CompleteWizardStep step)
1146                 {
1147                         CompleteStepContainer contentTemplateContainer = new CompleteStepContainer (this);
1148                         if (step.ContentTemplate != null) {
1149                                 step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1150                         }
1151                         else {
1152                                 new CompleteStepTemplate (this).InstantiateIn (contentTemplateContainer.InnerCell);
1153                                 contentTemplateContainer.ConfirmDefaultTemplate ();
1154                         }
1155
1156                         step.ContentTemplateContainer = contentTemplateContainer;
1157                         step.Controls.Clear ();
1158                         step.Controls.Add (contentTemplateContainer);
1159
1160                         BaseWizardNavigationContainer customNavigationTemplateContainer = new BaseWizardNavigationContainer ();
1161                         if (step.CustomNavigationTemplate != null) {
1162                                 step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1163                                 RegisterCustomNavigation (step, customNavigationTemplateContainer);
1164                         }
1165                         step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1166                 }
1167
1168                 void InstantiateCreateUserWizardStep (CreateUserWizardStep step)
1169                 {
1170                         CreateUserStepContainer contentTemplateContainer = new CreateUserStepContainer (this);
1171                         if (step.ContentTemplate != null) {
1172                                 step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1173                         }
1174                         else {
1175                                 new CreateUserStepTemplate (this).InstantiateIn (contentTemplateContainer.InnerCell);
1176                                 contentTemplateContainer.ConfirmDefaultTemplate ();
1177                                 contentTemplateContainer.EnsureValidatorsState ();
1178                         }
1179
1180                         step.ContentTemplateContainer = contentTemplateContainer;
1181                         step.Controls.Clear ();
1182                         step.Controls.Add (contentTemplateContainer);
1183
1184                         CreateUserNavigationContainer customNavigationTemplateContainer = new CreateUserNavigationContainer (this);
1185                         if (step.CustomNavigationTemplate != null) {
1186                                 step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1187                         }
1188                         else {
1189                                 new CreateUserStepNavigationTemplate (this).InstantiateIn (customNavigationTemplateContainer);
1190                                 customNavigationTemplateContainer.ConfirmDefaultTemplate ();
1191                         }
1192                         RegisterCustomNavigation (step, customNavigationTemplateContainer);
1193
1194                         step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1195                 }
1196                 
1197                 internal override ITemplate SideBarItemTemplate
1198                 {
1199                         get { return new SideBarLabelTemplate (this); }
1200                 }
1201
1202                 #endregion
1203
1204                 #region Protected Methods
1205
1206                 protected internal override void CreateChildControls ()
1207                 {
1208                         if (CreateUserStep == null)
1209                                 WizardSteps.AddAt (0, new CreateUserWizardStep ());
1210
1211                         if (CompleteStep == null)
1212                                 WizardSteps.AddAt (WizardSteps.Count, new CompleteWizardStep ());
1213
1214                         base.CreateChildControls ();
1215                 }
1216
1217                 protected override void CreateControlHierarchy ()
1218                 {
1219                         base.CreateControlHierarchy ();
1220
1221                         CreateUserStepContainer container = CreateUserStep.ContentTemplateContainer as CreateUserStepContainer;
1222
1223                         if (container != null) {
1224                                 IEditableTextControl editable;
1225                                 editable = container.UserNameTextBox as IEditableTextControl;
1226
1227                                 if (editable != null)
1228                                         editable.TextChanged += new EventHandler (UserName_TextChanged);
1229
1230                                 if (!AutoGeneratePassword) {
1231                                         editable = container.PasswordTextBox as IEditableTextControl;
1232
1233                                         if (editable != null)
1234                                                 editable.TextChanged += new EventHandler (Password_TextChanged);
1235
1236                                         editable = container.ConfirmPasswordTextBox as IEditableTextControl;
1237
1238                                         if (editable != null)
1239                                                 editable.TextChanged += new EventHandler (ConfirmPassword_TextChanged);
1240                                 }
1241
1242                                 if (RequireEmail) {
1243                                         editable = container.EmailTextBox as IEditableTextControl;
1244
1245                                         if (editable != null)
1246                                                 editable.TextChanged += new EventHandler (Email_TextChanged);
1247                                 }
1248
1249                                 if (QuestionAndAnswerRequired) {
1250                                         editable = container.QuestionTextBox as IEditableTextControl;
1251
1252                                         if (editable != null)
1253                                                 editable.TextChanged += new EventHandler (Question_TextChanged);
1254
1255                                         editable = container.AnswerTextBox as IEditableTextControl;
1256
1257                                         if (editable != null)
1258                                                 editable.TextChanged += new EventHandler (Answer_TextChanged);
1259                                 }
1260
1261                                 _errorMessageLabel = container.ErrorMessageLabel;
1262                         }
1263                 }
1264
1265                 [MonoTODO ("Not Implemented")]
1266                 protected override IDictionary GetDesignModeState ()
1267                 {
1268                         throw new NotImplementedException ();
1269                 }
1270
1271                 protected override bool OnBubbleEvent (object source, EventArgs e)
1272                 {
1273                         CommandEventArgs args = e as CommandEventArgs;
1274                         if (e != null && args.CommandName == ContinueButtonCommandName) {
1275                                 ProcessContinueEvent ();
1276                                 return true;
1277                         }
1278                         return base.OnBubbleEvent (source, e);
1279                 }
1280
1281                 private void ProcessContinueEvent () {
1282                         OnContinueButtonClick (EventArgs.Empty);
1283
1284                         if (ContinueDestinationPageUrl.Length > 0) {
1285                                 Context.Response.Redirect (ContinueDestinationPageUrl);
1286                         }
1287                 }
1288
1289                 protected virtual void OnContinueButtonClick (EventArgs e)
1290                 {
1291                         if (Events != null) {
1292                                 EventHandler eh = (EventHandler) Events [ContinueButtonClickEvent];
1293                                 if (eh != null) eh (this, e);
1294                         }
1295                 }
1296
1297                 protected virtual void OnCreatedUser (EventArgs e)
1298                 {
1299                         if (Events != null) {
1300                                 EventHandler eh = (EventHandler) Events [CreatedUserEvent];
1301                                 if (eh != null) eh (this, e);
1302                         }
1303                 }
1304
1305                 protected virtual void OnCreateUserError (CreateUserErrorEventArgs e)
1306                 {
1307                         if (Events != null) {
1308                                 CreateUserErrorEventHandler eh = (CreateUserErrorEventHandler) Events [CreateUserErrorEvent];
1309                                 if (eh != null) eh (this, e);
1310                         }
1311                 }
1312
1313                 protected virtual void OnCreatingUser (LoginCancelEventArgs e)
1314                 {
1315                         if (Events != null) {
1316                                 LoginCancelEventHandler eh = (LoginCancelEventHandler) Events [CreatingUserEvent];
1317                                 if (eh != null) eh (this, e);
1318                         }
1319                 }
1320
1321                 protected override void OnNextButtonClick (WizardNavigationEventArgs e)
1322                 {
1323                         if (ActiveStep == CreateUserStep) {
1324                                 bool userCreated = CreateUser ();
1325                                 if (!userCreated)
1326                                         e.Cancel = true;
1327                                 else
1328                                         if (LoginCreatedUser)
1329                                                 Login ();
1330                         }
1331                         base.OnNextButtonClick (e);
1332                 }
1333
1334                 protected internal override void OnPreRender (EventArgs e)
1335                 {
1336                         base.OnPreRender (e);
1337                 }
1338
1339                 protected virtual void OnSendingMail (MailMessageEventArgs e)
1340                 {
1341                         if (Events != null) {
1342                                 MailMessageEventHandler eh = (MailMessageEventHandler) Events [SendingMailEvent];
1343                                 if (eh != null) eh (this, e);
1344                         }
1345                 }
1346
1347                 protected virtual void OnSendMailError (SendMailErrorEventArgs e)
1348                 {
1349                         if (Events != null) {
1350                                 SendMailErrorEventHandler eh = (SendMailErrorEventHandler) Events [SendMailErrorEvent];
1351                                 if (eh != null) eh (this, e);
1352                         }
1353                 }
1354
1355                 protected override void LoadViewState (object savedState)
1356                 {
1357                         if (savedState == null) {
1358                                 base.LoadViewState (null);
1359                                 return;
1360                         }
1361
1362                         object [] states = (object []) savedState;
1363                         base.LoadViewState (states [0]);
1364
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]);
1387
1388                         ((CreateUserStepContainer) CreateUserStep.ContentTemplateContainer).EnsureValidatorsState ();
1389                 }
1390
1391                 protected override object SaveViewState ()
1392                 {
1393                         object [] state = new object [12];
1394                         state [0] = base.SaveViewState ();
1395
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 ();
1418
1419                         for (int n = 0; n < state.Length; n++)
1420                                 if (state [n] != null)
1421                                         return state;
1422
1423                         return null;
1424                 }
1425
1426                 [MonoTODO ("for design-time usage - no more details available")]
1427                 protected override void SetDesignModeState (IDictionary data)
1428                 {
1429                         base.SetDesignModeState (data);
1430                 }
1431
1432                 protected override void TrackViewState ()
1433                 {
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 ();
1457                 }
1458
1459                 #endregion
1460
1461                 #region Private event handlers
1462
1463                 private void UserName_TextChanged (object sender, EventArgs e)
1464                 {
1465                         UserName = ((ITextControl) sender).Text;
1466                 }
1467
1468                 private void Password_TextChanged (object sender, EventArgs e)
1469                 {
1470                         _password = ((ITextControl) sender).Text;
1471                 }
1472
1473                 private void ConfirmPassword_TextChanged (object sender, EventArgs e)
1474                 {
1475                         _confirmPassword = ((ITextControl) sender).Text;
1476                 }
1477
1478                 private void Email_TextChanged (object sender, EventArgs e)
1479                 {
1480                         Email = ((ITextControl) sender).Text;
1481                 }
1482
1483                 private void Question_TextChanged (object sender, EventArgs e)
1484                 {
1485                         Question = ((ITextControl) sender).Text;
1486                 }
1487
1488                 private void Answer_TextChanged (object sender, EventArgs e)
1489                 {
1490                         Answer = ((ITextControl) sender).Text;
1491                 }
1492
1493                 #endregion
1494
1495                 #region Private Methods
1496
1497                 private void InitMemberShipProvider ()
1498                 {
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));
1503                 }
1504
1505                 private bool CreateUser ()
1506                 {
1507                         if (!Page.IsValid)
1508                                 return false;
1509
1510                         if (AutoGeneratePassword)
1511                                 _password = GeneratePassword ();
1512
1513                         OnCreatingUser (new LoginCancelEventArgs (false));
1514
1515                         MembershipCreateStatus status;
1516                         MembershipUser newUser = MembershipProviderInternal.CreateUser (
1517                                 UserName, Password, Email, Question, Answer, !DisableCreatedUser, null, out status);
1518
1519                         if ((newUser != null) && (status == MembershipCreateStatus.Success)) {
1520                                 OnCreatedUser (new EventArgs ());
1521                                 return true;
1522                         }
1523
1524                         switch (status) {
1525                                 case MembershipCreateStatus.DuplicateUserName:
1526                                         ShowErrorMessage (DuplicateUserNameErrorMessage);
1527                                         break;
1528
1529                                 case MembershipCreateStatus.InvalidPassword:
1530                                         ShowErrorMessage (String.Format (InvalidPasswordErrorMessage, MembershipProviderInternal.MinRequiredPasswordLength, MembershipProviderInternal.MinRequiredNonAlphanumericCharacters));
1531                                         break;
1532
1533                                 case MembershipCreateStatus.DuplicateEmail:
1534                                         ShowErrorMessage (DuplicateEmailErrorMessage);
1535                                         break;
1536
1537                                 case MembershipCreateStatus.InvalidEmail:
1538                                         ShowErrorMessage (InvalidEmailErrorMessage);
1539                                         break;
1540
1541                                 case MembershipCreateStatus.InvalidQuestion:
1542                                         ShowErrorMessage (InvalidQuestionErrorMessage);
1543                                         break;
1544
1545                                 case MembershipCreateStatus.InvalidAnswer:
1546                                         ShowErrorMessage (InvalidAnswerErrorMessage);
1547                                         break;
1548
1549                                 case MembershipCreateStatus.UserRejected:
1550                                 case MembershipCreateStatus.InvalidUserName:
1551                                 case MembershipCreateStatus.ProviderError:
1552                                 case MembershipCreateStatus.InvalidProviderUserKey:
1553                                         ShowErrorMessage (UnknownErrorMessage);
1554                                         break;
1555
1556
1557                         }
1558
1559                         OnCreateUserError (new CreateUserErrorEventArgs (status));
1560
1561                         return false;
1562                 }
1563
1564                 private void Login ()
1565                 {
1566                         bool userValidated = MembershipProviderInternal.ValidateUser (UserName, Password);
1567                         if (userValidated)
1568                                 FormsAuthentication.SetAuthCookie (UserName, false);
1569                 }
1570
1571                 private void ShowErrorMessage (string errorMessage)
1572                 {
1573                         if (_errorMessageLabel != null)
1574                                 _errorMessageLabel.Text = errorMessage;
1575                 }
1576
1577                 private string GeneratePassword ()
1578                 {
1579                         return Membership.GeneratePassword (8, 3);
1580                 }
1581
1582                 #endregion
1583
1584                 #region SideBarLabelTemplate
1585
1586                 class SideBarLabelTemplate : ITemplate
1587                 {
1588                         Wizard wizard;
1589
1590                         public SideBarLabelTemplate (Wizard wizard)
1591                         {
1592                                 this.wizard = wizard;
1593                         }
1594
1595                         public void InstantiateIn (Control control)
1596                         {
1597                                 Label b = new Label ();
1598                                 wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1599                                 control.Controls.Add (b);
1600                                 control.DataBinding += Bound;
1601                         }
1602
1603                         void Bound (object s, EventArgs args)
1604                         {
1605                                 WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1606                                 if (step != null) {
1607                                         Control c = (Control) s;
1608                                         Label b = (Label) c.Controls [0];
1609                                         b.ID = SideBarButtonID;
1610                                         b.Text = step.Title;
1611                                 }
1612                         }
1613                 }
1614
1615                 #endregion
1616
1617                 sealed class CreateUserNavigationContainer : DefaultNavigationContainer
1618                 {
1619                         CreateUserWizard _createUserWizard;
1620
1621                         public CreateUserNavigationContainer (CreateUserWizard createUserWizard)
1622                                 : base (createUserWizard)
1623                         {
1624                                 _createUserWizard = createUserWizard;
1625                         }
1626
1627                         protected override void UpdateState ()
1628                         {
1629                                 // previous
1630                                 if (_createUserWizard.AllowNavigationToStep (_createUserWizard.ActiveStepIndex - 1)) {
1631                                         UpdateNavButtonState (Wizard.StepPreviousButtonID + Wizard.StepPreviousButtonType, Wizard.StepPreviousButtonText, Wizard.StepPreviousButtonImageUrl, Wizard.StepPreviousButtonStyle);
1632                                 }
1633                                 else {
1634                                         ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1635                                 }
1636
1637                                 // create user
1638                                 UpdateNavButtonState (Wizard.StepNextButtonID + _createUserWizard.CreateUserButtonType, _createUserWizard.CreateUserButtonText, _createUserWizard.CreateUserButtonImageUrl, _createUserWizard.CreateUserButtonStyle);
1639
1640                                 // cancel
1641                                 if (Wizard.DisplayCancelButton) {
1642                                         UpdateNavButtonState (Wizard.CancelButtonID + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1643                                 }
1644                                 else {
1645                                         ((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
1646                                 }
1647                         }
1648                 }
1649
1650                 sealed class CreateUserStepNavigationTemplate : ITemplate
1651                 {
1652                         readonly CreateUserWizard _createUserWizard;
1653
1654                         public CreateUserStepNavigationTemplate (CreateUserWizard createUserWizard) {
1655                                 _createUserWizard = createUserWizard;
1656                         }
1657
1658                         #region ITemplate Members
1659
1660                         public void InstantiateIn (Control container) {
1661                                 Table t = new Table ();
1662                                 t.CellPadding = 5;
1663                                 t.CellSpacing = 5;
1664                                 t.Width = Unit.Percentage (100);
1665                                 t.Height = Unit.Percentage (100);
1666                                 TableRow row = new TableRow ();
1667
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));
1671                                 
1672                                 t.Rows.Add (row);
1673                                 container.Controls.Add (t);
1674                         }
1675
1676                         void AddButtonCell (TableRow row, params Control [] controls)
1677                         {
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);
1683                         }
1684
1685                         #endregion
1686                 }
1687
1688                 sealed class CreateUserStepContainer : DefaultContentContainer
1689                 {
1690                         CreateUserWizard _createUserWizard;
1691
1692                         public CreateUserStepContainer (CreateUserWizard createUserWizard)
1693                                 : base (createUserWizard)
1694                         {
1695                                 _createUserWizard = createUserWizard;
1696                         }
1697
1698                         public Control UserNameTextBox {
1699                                 get {
1700                                         Control c = FindControl ("UserName");
1701                                         if (c == null)
1702                                                 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID UserName for the username.");
1703
1704                                         return c;
1705                                 }
1706                         }
1707                         public Control PasswordTextBox {
1708                                 get {
1709                                         Control c = FindControl ("Password");
1710                                         if (c == null)
1711                                                 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Password for the new password, this is required if AutoGeneratePassword = true.");
1712
1713                                         return c;
1714                                 }
1715                         }
1716                         public Control ConfirmPasswordTextBox {
1717                                 get {
1718                                         Control c = FindControl ("Password");
1719                                         return c;
1720                                 }
1721                         }
1722                         public Control EmailTextBox {
1723                                 get {
1724                                         Control c = FindControl ("Email");
1725                                         if (c == null)
1726                                                 throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Email for the e-mail, this is required if RequireEmail = true.");
1727
1728                                         return c;
1729                                 }
1730                         }
1731                         public Control QuestionTextBox {
1732                                 get {
1733                                         Control c = FindControl ("Question");
1734                                         if (c == null)
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.");
1736
1737                                         return c;
1738                                 }
1739                         }
1740                         public Control AnswerTextBox {
1741                                 get {
1742                                         Control c = FindControl ("Answer");
1743                                         if (c == null)
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.");
1745
1746                                         return c;
1747                                 }
1748                         }
1749                         public ITextControl ErrorMessageLabel {
1750                                 get { return FindControl ("ErrorMessage") as ITextControl; }
1751                         }
1752
1753                         protected override void UpdateState () {
1754                                 // Row #0 - title
1755                                 if (String.IsNullOrEmpty (_createUserWizard.CreateUserStep.Title)) {
1756                                         ((Table) InnerCell.Controls [0]).Rows [0].Visible = false;
1757                                 }
1758                                 else {
1759                                         ((Table) InnerCell.Controls [0]).Rows [0].Cells [0].Text = _createUserWizard.CreateUserStep.Title;
1760                                 }
1761
1762                                 // Row #1 - InstructionText
1763                                 if (String.IsNullOrEmpty (_createUserWizard.InstructionText)) {
1764                                         ((Table) InnerCell.Controls [0]).Rows [1].Visible = false;
1765                                 }
1766                                 else {
1767                                         ((Table) InnerCell.Controls [0]).Rows [1].Cells [0].Text = _createUserWizard.InstructionText;
1768                                 }
1769
1770                                 // Row #2
1771                                 Label UserNameLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [2].Cells [0].Controls [0];
1772                                 UserNameLabel.Text = _createUserWizard.UserNameLabelText;
1773
1774                                 RequiredFieldValidator UserNameRequired = (RequiredFieldValidator) FindControl ("UserNameRequired");
1775                                 UserNameRequired.ErrorMessage = _createUserWizard.UserNameRequiredErrorMessage;
1776                                 UserNameRequired.ToolTip = _createUserWizard.UserNameRequiredErrorMessage;
1777
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;
1782                                 }
1783                                 else {
1784                                         // Row #3
1785                                         Label PasswordLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [0];
1786                                         PasswordLabel.Text = _createUserWizard.PasswordLabelText;
1787
1788                                         RequiredFieldValidator PasswordRequired = (RequiredFieldValidator) FindControl ("PasswordRequired");
1789                                         PasswordRequired.ErrorMessage = _createUserWizard.PasswordRequiredErrorMessage;
1790                                         PasswordRequired.ToolTip = _createUserWizard.PasswordRequiredErrorMessage;
1791
1792                                         // Row #4
1793                                         if (String.IsNullOrEmpty (_createUserWizard.PasswordHintText)) {
1794                                                 ((Table) InnerCell.Controls [0]).Rows [4].Visible = false;
1795                                         }
1796                                         else {
1797                                                 ((Table) InnerCell.Controls [0]).Rows [4].Cells [1].Text = _createUserWizard.PasswordHintText;
1798                                         }
1799
1800                                         // Row #5
1801                                         Label ConfirmPasswordLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [5].Cells [0].Controls [0];
1802                                         ConfirmPasswordLabel.Text = _createUserWizard.ConfirmPasswordLabelText;
1803
1804                                         RequiredFieldValidator ConfirmPasswordRequired = (RequiredFieldValidator) FindControl ("ConfirmPasswordRequired");
1805                                         ConfirmPasswordRequired.ErrorMessage = _createUserWizard.ConfirmPasswordRequiredErrorMessage;
1806                                         ConfirmPasswordRequired.ToolTip = _createUserWizard.ConfirmPasswordRequiredErrorMessage;
1807                                 }
1808
1809                                 // Row #6
1810                                 if (_createUserWizard.RequireEmail) {
1811                                         Label EmailLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [6].Cells [0].Controls [0];
1812                                         EmailLabel.Text = _createUserWizard.EmailLabelText;
1813
1814                                         RequiredFieldValidator EmailRequired = (RequiredFieldValidator) FindControl ("EmailRequired");
1815                                         EmailRequired.ErrorMessage = _createUserWizard.EmailRequiredErrorMessage;
1816                                         EmailRequired.ToolTip = _createUserWizard.EmailRequiredErrorMessage;
1817                                 }
1818                                 else {
1819                                         ((Table) InnerCell.Controls [0]).Rows [6].Visible = false;
1820                                 }
1821
1822                                 if (_createUserWizard.QuestionAndAnswerRequired) {
1823                                         // Row #7
1824                                         Label QuestionLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [7].Cells [0].Controls [0];
1825                                         QuestionLabel.Text = _createUserWizard.QuestionLabelText;
1826
1827                                         RequiredFieldValidator QuestionRequired = (RequiredFieldValidator) FindControl ("QuestionRequired");
1828                                         QuestionRequired.ErrorMessage = _createUserWizard.QuestionRequiredErrorMessage;
1829                                         QuestionRequired.ToolTip = _createUserWizard.QuestionRequiredErrorMessage;
1830
1831                                         // Row #8
1832                                         Label AnswerLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [8].Cells [0].Controls [0];
1833                                         AnswerLabel.Text = _createUserWizard.AnswerLabelText;
1834
1835                                         RequiredFieldValidator AnswerRequired = (RequiredFieldValidator) FindControl ("AnswerRequired");
1836                                         AnswerRequired.ErrorMessage = _createUserWizard.AnswerRequiredErrorMessage;
1837                                         AnswerRequired.ToolTip = _createUserWizard.AnswerRequiredErrorMessage;
1838                                 }
1839                                 else {
1840                                         ((Table) InnerCell.Controls [0]).Rows [7].Visible = false;
1841                                         ((Table) InnerCell.Controls [0]).Rows [8].Visible = false;
1842                                 }
1843
1844                                 // Row #9
1845                                 if (_createUserWizard.AutoGeneratePassword) {
1846                                         ((Table) InnerCell.Controls [0]).Rows [9].Visible = false;
1847                                 }
1848                                 else {
1849                                         CompareValidator PasswordCompare = (CompareValidator) FindControl ("PasswordCompare");
1850                                         PasswordCompare.ErrorMessage = _createUserWizard.ConfirmPasswordCompareErrorMessage;
1851                                 }
1852
1853                                 // Row #10
1854                                 if (_createUserWizard.AutoGeneratePassword || String.IsNullOrEmpty (_createUserWizard.PasswordRegularExpression)) {
1855                                         ((Table) InnerCell.Controls [0]).Rows [10].Visible = false;
1856                                 }
1857                                 else {
1858                                         RegularExpressionValidator PasswordRegEx = (RegularExpressionValidator) FindControl ("PasswordRegEx");
1859                                         PasswordRegEx.ValidationExpression = _createUserWizard.PasswordRegularExpression;
1860                                         PasswordRegEx.ErrorMessage = _createUserWizard.PasswordRegularExpressionErrorMessage;
1861                                 }
1862
1863                                 // Row #11
1864                                 if (!_createUserWizard.RequireEmail || String.IsNullOrEmpty (_createUserWizard.EmailRegularExpression)) {
1865                                         ((Table) InnerCell.Controls [0]).Rows [11].Visible = false;
1866                                 }
1867                                 else {
1868                                         RegularExpressionValidator EmailRegEx = (RegularExpressionValidator) FindControl ("EmailRegEx");
1869                                         EmailRegEx.ErrorMessage = _createUserWizard.EmailRegularExpressionErrorMessage;
1870                                         EmailRegEx.ValidationExpression = _createUserWizard.EmailRegularExpression;
1871                                 }
1872
1873                                 // Row #12
1874                                 if (String.IsNullOrEmpty (ErrorMessageLabel.Text)) {
1875                                         ((Table) InnerCell.Controls [0]).Rows [12].Visible = false;
1876                                 }
1877
1878                                 // Row #13
1879                                 // HelpPageIconUrl
1880                                 Image img = (Image) ((Table) InnerCell.Controls [0]).Rows [13].Cells [0].Controls [0];
1881                                 if (String.IsNullOrEmpty (_createUserWizard.HelpPageIconUrl)) {
1882                                         img.Visible = false;
1883                                 }
1884                                 else {
1885                                         img.ImageUrl = _createUserWizard.HelpPageIconUrl;
1886                                         img.AlternateText = _createUserWizard.HelpPageText;
1887                                 }
1888
1889                                 // 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;
1893                                 }
1894                                 else {
1895                                         link.Text = _createUserWizard.HelpPageText;
1896                                         link.NavigateUrl = _createUserWizard.HelpPageUrl;
1897                                 }
1898
1899                                 ((Table) InnerCell.Controls [0]).Rows [13].Visible = img.Visible || link.Visible;
1900
1901                         }
1902
1903                         public void EnsureValidatorsState ()
1904                         {
1905                                 if (!IsDefaultTemplate)
1906                                         return;
1907
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;
1914
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;
1919
1920                                 ((RequiredFieldValidator) FindControl ("QuestionRequired")).Enabled = _createUserWizard.QuestionAndAnswerRequired;
1921                                 ((RequiredFieldValidator) FindControl ("AnswerRequired")).Enabled = _createUserWizard.QuestionAndAnswerRequired;
1922                         }
1923                 }
1924
1925                 sealed class CreateUserStepTemplate : ITemplate
1926                 {
1927                         readonly CreateUserWizard _createUserWizard;
1928
1929                         public CreateUserStepTemplate (CreateUserWizard createUserWizard)
1930                         {
1931                                 _createUserWizard = createUserWizard;
1932                         }
1933
1934                         #region ITemplate Members
1935
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 ();
1940
1941                                 if (c0 != null)
1942                                         cell0.Controls.Add (c0);
1943                                 row.Controls.Add (cell0);
1944
1945                                 if ((c1 != null) && (c2 != null)) {
1946                                         cell1.Controls.Add (c1);
1947                                         cell1.Controls.Add (c2);
1948                                         cell0.HorizontalAlign = HorizontalAlign.Right;
1949
1950                                         if (s0 != null)
1951                                                 _createUserWizard.RegisterApplyStyle (cell0, s0);
1952                                         if (s1 != null)
1953                                                 _createUserWizard.RegisterApplyStyle (cell1, s1);
1954
1955                                         row.Controls.Add (cell1);
1956                                 }
1957                                 else {
1958                                         cell0.ColumnSpan = 2;
1959                                         cell0.HorizontalAlign = HorizontalAlign.Center;
1960                                         if (s0 != null)
1961                                                 _createUserWizard.RegisterApplyStyle (cell0, s0);
1962                                 }
1963                                 return row;
1964                         }
1965
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);
1970
1971                                 // Row #0
1972                                 table.Controls.Add (CreateRow (null, null, null, _createUserWizard.TitleTextStyle, null));
1973
1974                                 // Row #1
1975                                 table.Controls.Add (CreateRow (null, null, null, _createUserWizard.InstructionTextStyle, null));
1976
1977                                 // Row #2
1978                                 TextBox UserName = new TextBox ();
1979                                 UserName.ID = "UserName";
1980                                 _createUserWizard.RegisterApplyStyle (UserName, _createUserWizard.TextBoxStyle);
1981
1982                                 Label UserNameLabel = new Label ();
1983                                 UserNameLabel.AssociatedControlID = "UserName";
1984
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);
1994
1995                                 table.Controls.Add (CreateRow (UserNameLabel, UserName, UserNameRequired, _createUserWizard.LabelStyle, null));
1996
1997                                 // Row #3
1998                                 TextBox Password = new TextBox ();
1999                                 Password.ID = "Password";
2000                                 Password.TextMode = TextBoxMode.Password;
2001                                 _createUserWizard.RegisterApplyStyle (Password, _createUserWizard.TextBoxStyle);
2002
2003                                 Label PasswordLabel = new Label ();
2004                                 PasswordLabel.AssociatedControlID = "Password";
2005
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);
2014
2015                                 table.Controls.Add (CreateRow (PasswordLabel, Password, PasswordRequired, _createUserWizard.LabelStyle, null));
2016
2017                                 // Row #4
2018                                 table.Controls.Add (CreateRow (new LiteralControl (""), new LiteralControl (""), new LiteralControl (""), null, _createUserWizard.PasswordHintStyle));
2019
2020                                 // Row #5
2021                                 TextBox ConfirmPassword = new TextBox ();
2022                                 ConfirmPassword.ID = "ConfirmPassword";
2023                                 ConfirmPassword.TextMode = TextBoxMode.Password;
2024                                 _createUserWizard.RegisterApplyStyle (ConfirmPassword, _createUserWizard.TextBoxStyle);
2025
2026                                 Label ConfirmPasswordLabel = new Label ();
2027                                 ConfirmPasswordLabel.AssociatedControlID = "ConfirmPassword";
2028
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);
2036
2037                                 table.Controls.Add (CreateRow (ConfirmPasswordLabel, ConfirmPassword, ConfirmPasswordRequired, _createUserWizard.LabelStyle, null));
2038
2039                                 // Row #6
2040                                 TextBox Email = new TextBox ();
2041                                 Email.ID = "Email";
2042                                 _createUserWizard.RegisterApplyStyle (Email, _createUserWizard.TextBoxStyle);
2043
2044                                 Label EmailLabel = new Label ();
2045                                 EmailLabel.AssociatedControlID = "Email";
2046
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);
2054
2055                                 table.Controls.Add (CreateRow (EmailLabel, Email, EmailRequired, _createUserWizard.LabelStyle, null));
2056
2057                                 // Row #7
2058                                 TextBox Question = new TextBox ();
2059                                 Question.ID = "Question";
2060                                 _createUserWizard.RegisterApplyStyle (Question, _createUserWizard.TextBoxStyle);
2061
2062                                 Label QuestionLabel = new Label ();
2063                                 QuestionLabel.AssociatedControlID = "Question";
2064
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);
2072
2073                                 table.Controls.Add (CreateRow (QuestionLabel, Question, QuestionRequired, _createUserWizard.LabelStyle, null));
2074
2075                                 // Row #8
2076                                 TextBox Answer = new TextBox ();
2077                                 Answer.ID = "Answer";
2078                                 _createUserWizard.RegisterApplyStyle (Answer, _createUserWizard.TextBoxStyle);
2079
2080                                 Label AnswerLabel = new Label ();
2081                                 AnswerLabel.AssociatedControlID = "Answer";
2082
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);
2090
2091                                 table.Controls.Add (CreateRow (AnswerLabel, Answer, AnswerRequired, _createUserWizard.LabelStyle, null));
2092
2093                                 // Row #9
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);
2103
2104                                 table.Controls.Add (CreateRow (PasswordCompare, null, null, null, null));
2105
2106                                 // Row #10
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);
2115
2116                                 table.Controls.Add (CreateRow (PasswordRegEx, null, null, null, null));
2117
2118                                 // Row #11
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);
2127
2128                                 table.Controls.Add (CreateRow (EmailRegEx, null, null, null, null));
2129
2130                                 // Row #12
2131                                 Label ErrorMessage = new Label ();
2132                                 ErrorMessage.ID = "ErrorMessage";
2133                                 ErrorMessage.EnableViewState = false;
2134                                 _createUserWizard.RegisterApplyStyle (ErrorMessage, _createUserWizard.ValidatorTextStyle);
2135
2136                                 table.Controls.Add (CreateRow (ErrorMessage, null, null, null, null));
2137
2138                                 // Row #13
2139                                 TableRow row13 = CreateRow (new Image (), null, null, null, null);
2140
2141                                 HyperLink HelpLink = new HyperLink ();
2142                                 HelpLink.ID = "HelpLink";
2143                                 _createUserWizard.RegisterApplyStyle (HelpLink, _createUserWizard.HyperLinkStyle);
2144                                 row13.Cells [0].Controls.Add (HelpLink);
2145
2146                                 row13.Cells [0].HorizontalAlign = HorizontalAlign.Left;
2147                                 table.Controls.Add (row13);
2148
2149                                 //
2150                                 container.Controls.Add (table);
2151                         }
2152
2153                         #endregion
2154                 }
2155
2156                 sealed class CompleteStepContainer : DefaultContentContainer
2157                 {
2158                         CreateUserWizard _createUserWizard;
2159
2160                         public CompleteStepContainer (CreateUserWizard createUserWizard)
2161                                 : base (createUserWizard)
2162                         {
2163                                 _createUserWizard = createUserWizard;
2164                         }
2165
2166                         protected override void UpdateState ()
2167                         {
2168                                 // title
2169                                 if (String.IsNullOrEmpty (_createUserWizard.CompleteStep.Title)) {
2170                                         ((Table) InnerCell.Controls [0]).Rows [0].Visible = false;
2171                                 }
2172                                 else {
2173                                         ((Table) InnerCell.Controls [0]).Rows [0].Cells [0].Text = _createUserWizard.CompleteStep.Title;
2174                                 }
2175
2176                                 // CompleteSuccessText
2177                                 if (String.IsNullOrEmpty (_createUserWizard.CompleteSuccessText)) {
2178                                         ((Table) InnerCell.Controls [0]).Rows [1].Visible = false;
2179                                 }
2180                                 else {
2181                                         ((Table) InnerCell.Controls [0]).Rows [1].Cells [0].Text = _createUserWizard.CompleteSuccessText;
2182                                 }
2183
2184                                 // ContinueButton
2185                                 UpdateNavButtonState ("ContinueButton" + _createUserWizard.ContinueButtonType, _createUserWizard.ContinueButtonText, _createUserWizard.ContinueButtonImageUrl, _createUserWizard.ContinueButtonStyle);
2186
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;
2191                                 }
2192                                 else {
2193                                         img.ImageUrl = _createUserWizard.EditProfileIconUrl;
2194                                         img.AlternateText = _createUserWizard.EditProfileText;
2195                                 }
2196
2197                                 // 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;
2201                                 }
2202                                 else {
2203                                         link.Text = _createUserWizard.EditProfileText;
2204                                         link.NavigateUrl = _createUserWizard.EditProfileUrl;
2205                                 }
2206
2207                                 ((Table) InnerCell.Controls [0]).Rows [3].Visible = img.Visible || link.Visible;
2208                         }
2209                                 
2210                         void UpdateNavButtonState (string id, string text, string image, Style style)
2211                         {
2212                                 WebControl b = (WebControl) FindControl (id);
2213                                 foreach (Control c in b.Parent.Controls)
2214                                         c.Visible = b == c;
2215
2216                                 ((IButtonControl) b).Text = text;
2217                                 ImageButton imgbtn = b as ImageButton;
2218                                 if (imgbtn != null)
2219                                         imgbtn.ImageUrl = image;
2220
2221                                 b.ApplyStyle (style);
2222                         }
2223                 }
2224
2225                 sealed class CompleteStepTemplate : ITemplate
2226                 {
2227                         readonly CreateUserWizard _createUserWizard;
2228
2229                         public CompleteStepTemplate (CreateUserWizard createUserWizard)
2230                         {
2231                                 _createUserWizard = createUserWizard;
2232                         }
2233
2234                         #region ITemplate Members
2235
2236                         public void InstantiateIn (Control container)
2237                         {
2238                                 Table table = new Table ();
2239
2240                                 // Row #0
2241                                 TableRow row0 = new TableRow ();
2242                                 TableCell cell00 = new TableCell ();
2243
2244                                 cell00.HorizontalAlign = HorizontalAlign.Center;
2245                                 cell00.ColumnSpan = 2;
2246                                 _createUserWizard.RegisterApplyStyle (cell00, _createUserWizard.TitleTextStyle);
2247                                 row0.Cells.Add (cell00);
2248
2249                                 // Row #1
2250                                 TableRow row1 = new TableRow ();
2251                                 TableCell cell10 = new TableCell ();
2252
2253                                 cell10.HorizontalAlign = HorizontalAlign.Center;
2254                                 _createUserWizard.RegisterApplyStyle (cell10, _createUserWizard.CompleteSuccessTextStyle);
2255                                 row1.Cells.Add (cell10);
2256
2257                                 // Row #2
2258                                 TableRow row2 = new TableRow ();
2259                                 TableCell cell20 = new TableCell ();
2260
2261                                 cell20.HorizontalAlign = HorizontalAlign.Right;
2262                                 cell20.ColumnSpan = 2;
2263                                 row2.Cells.Add (cell20);
2264
2265                                 Control[] b = _createUserWizard.CreateButtonSet ("ContinueButton", CreateUserWizard.ContinueButtonCommandName);
2266                                 for (int i = 0; i < b.Length; i++)
2267                                         cell20.Controls.Add (b [i]);
2268
2269                                 // Row #3
2270                                 TableRow row3 = new TableRow ();
2271                                 TableCell cell30 = new TableCell ();
2272
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);
2279
2280                                 // table
2281                                 table.Rows.Add (row0);
2282                                 table.Rows.Add (row1);
2283                                 table.Rows.Add (row2);
2284                                 table.Rows.Add (row3);
2285
2286                                 container.Controls.Add (table);
2287                         }
2288
2289                         #endregion
2290                 }
2291         }
2292 }
2293
2294 #endif