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