2 // System.Web.UI.WebControls.Wizard
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.ComponentModel;
37 namespace System.Web.UI.WebControls
39 [DefaultEventAttribute ("FinishButtonClick")]
40 [BindableAttribute (false)]
41 [DesignerAttribute ("System.Web.UI.Design.WebControls.WizardDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
42 [ToolboxData ("<{0}:Wizard runat=\"server\"> <WizardSteps> <asp:WizardStep title=\"Step 1\" runat=\"server\"></asp:WizardStep> <asp:WizardStep title=\"Step 2\" runat=\"server\"></asp:WizardStep> </WizardSteps> </{0}:Wizard>")]
43 public class Wizard: CompositeControl
45 public static readonly string CancelCommandName = "Cancel";
46 public static readonly string MoveCompleteCommandName = "MoveComplete";
47 public static readonly string MoveNextCommandName = "MoveNext";
48 public static readonly string MovePreviousCommandName = "MovePrevious";
49 public static readonly string MoveToCommandName = "Move";
51 protected static readonly string CancelButtonID = "CancelButton";
52 protected static readonly string CustomFinishButtonID = "CustomFinishButton";
53 protected static readonly string CustomNextButtonID = "CustomNextButton";
54 protected static readonly string CustomPreviousButtonID = "CustomPreviousButton";
55 protected static readonly string DataListID = "SideBarList";
56 protected static readonly string FinishButtonID = "FinishButton";
57 protected static readonly string FinishPreviousButtonID = "FinishPreviousButton";
58 protected static readonly string SideBarButtonID = "SideBarButton";
59 protected static readonly string StartNextButtonID = "StartNextButton";
60 protected static readonly string StepNextButtonID = "StepNextButton";
61 protected static readonly string StepPreviousButtonID = "StepPreviousButton";
63 WizardStepCollection steps;
67 TableItemStyle stepStyle;
68 TableItemStyle sideBarStyle;
69 TableItemStyle headerStyle;
70 TableItemStyle navigationStyle;
71 Style sideBarButtonStyle;
73 Style cancelButtonStyle;
74 Style finishCompleteButtonStyle;
75 Style finishPreviousButtonStyle;
76 Style startNextButtonStyle;
77 Style stepNextButtonStyle;
78 Style stepPreviousButtonStyle;
79 Style navigationButtonStyle;
81 ITemplate finishNavigationTemplate;
82 ITemplate startNavigationTemplate;
83 ITemplate stepNavigationTemplate;
84 ITemplate headerTemplate;
85 ITemplate sideBarTemplate;
94 DataList stepDatalist;
95 ArrayList styles = new ArrayList ();
96 SideBarButtonTemplate sideBarItemTemplate;
98 private static readonly object ActiveStepChangedEvent = new object();
99 private static readonly object CancelButtonClickEvent = new object();
100 private static readonly object FinishButtonClickEvent = new object();
101 private static readonly object NextButtonClickEvent = new object();
102 private static readonly object PreviousButtonClickEvent = new object();
103 private static readonly object SideBarButtonClickEvent = new object();
107 sideBarItemTemplate = new SideBarButtonTemplate (this);
110 public event EventHandler ActiveStepChanged {
111 add { Events.AddHandler (ActiveStepChangedEvent, value); }
112 remove { Events.RemoveHandler (ActiveStepChangedEvent, value); }
115 public event EventHandler CancelButtonClick {
116 add { Events.AddHandler (CancelButtonClickEvent, value); }
117 remove { Events.RemoveHandler (CancelButtonClickEvent, value); }
120 public event WizardNavigationEventHandler FinishButtonClick {
121 add { Events.AddHandler (FinishButtonClickEvent, value); }
122 remove { Events.RemoveHandler (FinishButtonClickEvent, value); }
125 public event WizardNavigationEventHandler NextButtonClick {
126 add { Events.AddHandler (NextButtonClickEvent, value); }
127 remove { Events.RemoveHandler (NextButtonClickEvent, value); }
130 public event WizardNavigationEventHandler PreviousButtonClick {
131 add { Events.AddHandler (PreviousButtonClickEvent, value); }
132 remove { Events.RemoveHandler (PreviousButtonClickEvent, value); }
135 public event WizardNavigationEventHandler SideBarButtonClick {
136 add { Events.AddHandler (SideBarButtonClickEvent, value); }
137 remove { Events.RemoveHandler (SideBarButtonClickEvent, value); }
140 protected virtual void OnActiveStepChanged (object source, EventArgs e)
142 if (Events != null) {
143 EventHandler eh = (EventHandler) Events [ActiveStepChangedEvent];
144 if (eh != null) eh (source, e);
148 protected virtual void OnCancelButtonClick (EventArgs e)
150 if (Events != null) {
151 EventHandler eh = (EventHandler) Events [CancelButtonClickEvent];
152 if (eh != null) eh (this, e);
156 protected virtual void OnFinishButtonClick (WizardNavigationEventArgs e)
158 if (Events != null) {
159 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [FinishButtonClickEvent];
160 if (eh != null) eh (this, e);
164 protected virtual void OnNextButtonClick (WizardNavigationEventArgs e)
166 if (Events != null) {
167 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [NextButtonClickEvent];
168 if (eh != null) eh (this, e);
172 protected virtual void OnPreviousButtonClick (WizardNavigationEventArgs e)
174 if (Events != null) {
175 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [PreviousButtonClickEvent];
176 if (eh != null) eh (this, e);
180 protected virtual void OnSideBarButtonClick (WizardNavigationEventArgs e)
182 if (Events != null) {
183 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [SideBarButtonClickEvent];
184 if (eh != null) eh (this, e);
188 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
189 [BrowsableAttribute (false)]
190 public WizardStepBase ActiveStep {
192 if (ActiveStepIndex < -1 || ActiveStepIndex >= WizardSteps.Count)
193 throw new InvalidOperationException ("ActiveStepIndex has an invalid value.");
194 if (ActiveStepIndex == -1) return null;
195 return WizardSteps [activeStepIndex];
199 [DefaultValueAttribute (-1)]
200 [ThemeableAttribute (false)]
201 public virtual int ActiveStepIndex {
203 if (WizardSteps.Count == 0)
206 return activeStepIndex;
209 if (!AllowNavigationToStep (value))
211 if (activeStepIndex != value) {
212 if (history == null) history = new ArrayList ();
213 history.Insert (0, activeStepIndex);
215 activeStepIndex = value;
217 OnActiveStepChanged (this, EventArgs.Empty);
221 [UrlPropertyAttribute]
222 [DefaultValueAttribute ("")]
223 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
224 public virtual string CancelButtonImageUrl {
226 object v = ViewState ["CancelButtonImageUrl"];
227 return v != null ? (string)v : string.Empty;
230 ViewState ["CancelButtonImageUrl"] = value;
235 [DefaultValueAttribute (null)]
236 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
237 [NotifyParentPropertyAttribute (true)]
238 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
239 public Style CancelButtonStyle {
241 if (cancelButtonStyle == null) {
242 cancelButtonStyle = new Style ();
243 if (IsTrackingViewState)
244 ((IStateManager)cancelButtonStyle).TrackViewState ();
246 return cancelButtonStyle;
250 [LocalizableAttribute (true)]
251 public virtual string CancelButtonText {
253 object v = ViewState ["CancelButtonText"];
254 return v != null ? (string)v : "Cancel";
257 ViewState ["CancelButtonText"] = value;
262 [DefaultValueAttribute (ButtonType.Button)]
263 public virtual ButtonType CancelButtonType {
265 object v = ViewState ["CancelButtonType"];
266 return v != null ? (ButtonType)v : ButtonType.Button;
269 ViewState ["CancelButtonType"] = value;
274 [UrlPropertyAttribute]
275 [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
276 [DefaultValueAttribute ("")]
277 public virtual string CancelDestinationPageUrl {
279 object v = ViewState ["CancelDestinationPageUrl"];
280 return v != null ? (string)v : string.Empty;
283 ViewState ["CancelDestinationPageUrl"] = value;
287 [DefaultValueAttribute (0)]
288 public virtual int CellPadding {
290 object v = ViewState ["CellPadding"];
291 return v != null ? (int)v : 0;
294 ViewState ["CellPadding"] = value;
299 [DefaultValueAttribute (0)]
300 public virtual int CellSpacing {
302 object v = ViewState ["CellSpacing"];
303 return v != null ? (int)v : 0;
306 ViewState ["CellSpacing"] = value;
311 [DefaultValueAttribute (false)]
312 [ThemeableAttribute (false)]
313 public virtual bool DisplayCancelButton {
315 object v = ViewState ["DisplayCancelButton"];
316 return v != null ? (bool) v : false;
319 ViewState ["DisplayCancelButton"] = value;
324 [DefaultValueAttribute (true)]
325 [ThemeableAttribute (false)]
326 public virtual bool DisplaySideBar {
328 object v = ViewState ["DisplaySideBar"];
329 return v != null ? (bool) v : true;
332 ViewState ["DisplaySideBar"] = value;
337 [UrlPropertyAttribute]
338 [DefaultValueAttribute ("")]
339 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
340 public virtual string FinishCompleteButtonImageUrl {
342 object v = ViewState ["FinishCompleteButtonImageUrl"];
343 return v != null ? (string)v : string.Empty;
346 ViewState ["FinishCompleteButtonImageUrl"] = value;
351 [DefaultValueAttribute (null)]
352 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
353 [NotifyParentPropertyAttribute (true)]
354 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
355 public Style FinishCompleteButtonStyle {
357 if (finishCompleteButtonStyle == null) {
358 finishCompleteButtonStyle = new Style ();
359 if (IsTrackingViewState)
360 ((IStateManager)finishCompleteButtonStyle).TrackViewState ();
362 return finishCompleteButtonStyle;
366 [LocalizableAttribute (true)]
367 public virtual string FinishCompleteButtonText {
369 object v = ViewState ["FinishCompleteButtonText"];
370 return v != null ? (string)v : "Finish";
373 ViewState ["FinishCompleteButtonText"] = value;
378 [DefaultValueAttribute (ButtonType.Button)]
379 public virtual ButtonType FinishCompleteButtonType {
381 object v = ViewState ["FinishCompleteButtonType"];
382 return v != null ? (ButtonType)v : ButtonType.Button;
385 ViewState ["FinishCompleteButtonType"] = value;
390 [UrlPropertyAttribute]
391 [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
392 [DefaultValueAttribute ("")]
393 public virtual string FinishDestinationPageUrl {
395 object v = ViewState ["FinishDestinationPageUrl"];
396 return v != null ? (string)v : string.Empty;
399 ViewState ["FinishDestinationPageUrl"] = value;
403 [DefaultValue (null)]
404 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
405 [PersistenceMode (PersistenceMode.InnerProperty)]
407 public virtual ITemplate FinishNavigationTemplate {
408 get { return finishNavigationTemplate; }
409 set { finishNavigationTemplate = value; UpdateControls (); }
412 [UrlPropertyAttribute]
413 [DefaultValueAttribute ("")]
414 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
415 public virtual string FinishPreviousButtonImageUrl {
417 object v = ViewState ["FinishPreviousButtonImageUrl"];
418 return v != null ? (string)v : string.Empty;
421 ViewState ["FinishPreviousButtonImageUrl"] = value;
426 [DefaultValueAttribute (null)]
427 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
428 [NotifyParentPropertyAttribute (true)]
429 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
430 public Style FinishPreviousButtonStyle {
432 if (finishPreviousButtonStyle == null) {
433 finishPreviousButtonStyle = new Style ();
434 if (IsTrackingViewState)
435 ((IStateManager)finishPreviousButtonStyle).TrackViewState ();
437 return finishPreviousButtonStyle;
441 [LocalizableAttribute (true)]
442 public virtual string FinishPreviousButtonText {
444 object v = ViewState ["FinishPreviousButtonText"];
445 return v != null ? (string)v : "Previous";
448 ViewState ["FinishPreviousButtonText"] = value;
453 [DefaultValueAttribute (ButtonType.Button)]
454 public virtual ButtonType FinishPreviousButtonType {
456 object v = ViewState ["FinishPreviousButtonType"];
457 return v != null ? (ButtonType)v : ButtonType.Button;
460 ViewState ["FinishPreviousButtonType"] = value;
465 [DefaultValueAttribute (null)]
466 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
467 [NotifyParentPropertyAttribute (true)]
468 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
469 public TableItemStyle HeaderStyle {
471 if (headerStyle == null) {
472 headerStyle = new TableItemStyle ();
473 if (IsTrackingViewState)
474 ((IStateManager)headerStyle).TrackViewState ();
480 [DefaultValue (null)]
481 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
482 [PersistenceMode (PersistenceMode.InnerProperty)]
484 public virtual ITemplate HeaderTemplate {
485 get { return headerTemplate; }
486 set { headerTemplate = value; UpdateControls (); }
489 [DefaultValueAttribute ("")]
490 [LocalizableAttribute (true)]
491 public virtual string HeaderText {
493 object v = ViewState ["HeaderText"];
494 return v != null ? (string)v : string.Empty;
497 ViewState ["HeaderText"] = value;
502 [DefaultValueAttribute (null)]
503 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
504 [NotifyParentPropertyAttribute (true)]
505 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
506 public Style NavigationButtonStyle {
508 if (navigationButtonStyle == null) {
509 navigationButtonStyle = new Style ();
510 if (IsTrackingViewState)
511 ((IStateManager)navigationButtonStyle).TrackViewState ();
513 return navigationButtonStyle;
517 [DefaultValueAttribute (null)]
518 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
519 [NotifyParentPropertyAttribute (true)]
520 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
521 public TableItemStyle NavigationStyle {
523 if (navigationStyle == null) {
524 navigationStyle = new TableItemStyle ();
525 if (IsTrackingViewState)
526 ((IStateManager)navigationStyle).TrackViewState ();
528 return navigationStyle;
532 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
533 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
534 [DefaultValueAttribute (null)]
535 [NotifyParentPropertyAttribute (true)]
536 public TableItemStyle SideBarStyle {
538 if (sideBarStyle == null) {
539 sideBarStyle = new TableItemStyle ();
540 if (IsTrackingViewState)
541 ((IStateManager)sideBarStyle).TrackViewState ();
547 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
548 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
549 [DefaultValueAttribute (null)]
550 [NotifyParentPropertyAttribute (true)]
551 public Style SideBarButtonStyle {
553 if (sideBarButtonStyle == null) {
554 sideBarButtonStyle = new Style ();
555 if (IsTrackingViewState)
556 ((IStateManager)sideBarButtonStyle).TrackViewState ();
558 return sideBarButtonStyle;
562 [DefaultValue (null)]
563 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
564 [PersistenceMode (PersistenceMode.InnerProperty)]
566 public virtual ITemplate SideBarTemplate {
567 get { return sideBarTemplate; }
568 set { sideBarTemplate = value; UpdateControls (); }
573 public virtual string SkipLinkText
577 object v = ViewState ["SkipLinkText"];
578 return v != null ? (string) v : "Skip Navigation Links.";
582 ViewState ["SkipLinkText"] = value;
586 [DefaultValue (null)]
587 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
588 [PersistenceMode (PersistenceMode.InnerProperty)]
590 public virtual ITemplate StartNavigationTemplate {
591 get { return startNavigationTemplate; }
592 set { startNavigationTemplate = value; UpdateControls (); }
595 [UrlPropertyAttribute]
596 [DefaultValueAttribute ("")]
597 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
598 public virtual string StartNextButtonImageUrl {
600 object v = ViewState ["StartNextButtonImageUrl"];
601 return v != null ? (string)v : string.Empty;
604 ViewState ["StartNextButtonImageUrl"] = value;
609 [DefaultValueAttribute (null)]
610 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
611 [NotifyParentPropertyAttribute (true)]
612 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
613 public Style StartNextButtonStyle {
615 if (startNextButtonStyle == null) {
616 startNextButtonStyle = new Style ();
617 if (IsTrackingViewState)
618 ((IStateManager)startNextButtonStyle).TrackViewState ();
620 return startNextButtonStyle;
624 [LocalizableAttribute (true)]
625 public virtual string StartNextButtonText {
627 object v = ViewState ["StartNextButtonText"];
628 return v != null ? (string)v : "Next";
631 ViewState ["StartNextButtonText"] = value;
636 [DefaultValueAttribute (ButtonType.Button)]
637 public virtual ButtonType StartNextButtonType {
639 object v = ViewState ["StartNextButtonType"];
640 return v != null ? (ButtonType)v : ButtonType.Button;
643 ViewState ["StartNextButtonType"] = value;
648 [DefaultValue (null)]
649 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
650 [PersistenceMode (PersistenceMode.InnerProperty)]
652 public virtual ITemplate StepNavigationTemplate {
653 get { return stepNavigationTemplate; }
654 set { stepNavigationTemplate = value; UpdateControls (); }
657 [UrlPropertyAttribute]
658 [DefaultValueAttribute ("")]
659 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
660 public virtual string StepNextButtonImageUrl {
662 object v = ViewState ["StepNextButtonImageUrl"];
663 return v != null ? (string)v : string.Empty;
666 ViewState ["StepNextButtonImageUrl"] = value;
671 [DefaultValueAttribute (null)]
672 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
673 [NotifyParentPropertyAttribute (true)]
674 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
675 public Style StepNextButtonStyle {
677 if (stepNextButtonStyle == null) {
678 stepNextButtonStyle = new Style ();
679 if (IsTrackingViewState)
680 ((IStateManager)stepNextButtonStyle).TrackViewState ();
682 return stepNextButtonStyle;
686 [LocalizableAttribute (true)]
687 public virtual string StepNextButtonText {
689 object v = ViewState ["StepNextButtonText"];
690 return v != null ? (string)v : "Next";
693 ViewState ["StepNextButtonText"] = value;
698 [DefaultValueAttribute (ButtonType.Button)]
699 public virtual ButtonType StepNextButtonType {
701 object v = ViewState ["StepNextButtonType"];
702 return v != null ? (ButtonType)v : ButtonType.Button;
705 ViewState ["StepNextButtonType"] = value;
710 [UrlPropertyAttribute]
711 [DefaultValueAttribute ("")]
712 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
713 public virtual string StepPreviousButtonImageUrl {
715 object v = ViewState ["StepPreviousButtonImageUrl"];
716 return v != null ? (string)v : string.Empty;
719 ViewState ["StepPreviousButtonImageUrl"] = value;
724 [DefaultValueAttribute (null)]
725 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
726 [NotifyParentPropertyAttribute (true)]
727 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
728 public Style StepPreviousButtonStyle {
730 if (stepPreviousButtonStyle == null) {
731 stepPreviousButtonStyle = new Style ();
732 if (IsTrackingViewState)
733 ((IStateManager)stepPreviousButtonStyle).TrackViewState ();
735 return stepPreviousButtonStyle;
739 [LocalizableAttribute (true)]
740 public virtual string StepPreviousButtonText {
742 object v = ViewState ["StepPreviousButtonText"];
743 return v != null ? (string)v : "Previous";
746 ViewState ["StepPreviousButtonText"] = value;
751 [DefaultValueAttribute (ButtonType.Button)]
752 public virtual ButtonType StepPreviousButtonType {
754 object v = ViewState ["StepPreviousButtonType"];
755 return v != null ? (ButtonType)v : ButtonType.Button;
758 ViewState ["StepPreviousButtonType"] = value;
763 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
764 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
765 [DefaultValueAttribute (null)]
766 [NotifyParentPropertyAttribute (true)]
767 public TableItemStyle StepStyle {
769 if (stepStyle == null) {
770 stepStyle = new TableItemStyle ();
771 if (IsTrackingViewState)
772 ((IStateManager)stepStyle).TrackViewState ();
778 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
779 [EditorAttribute ("System.Web.UI.Design.WebControls.WizardStepCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
780 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
781 [ThemeableAttribute (false)]
782 public virtual WizardStepCollection WizardSteps {
785 steps = new WizardStepCollection (this);
791 protected virtual new HtmlTextWriterTag TagKey
794 return HtmlTextWriterTag.Table;
798 internal virtual ITemplate SideBarItemTemplate
800 get { return sideBarItemTemplate; }
803 public ICollection GetHistory ()
805 if (history == null) history = new ArrayList ();
809 public void MoveTo (WizardStepBase wizardStep)
811 if (wizardStep == null) throw new ArgumentNullException ("wizardStep");
813 int i = WizardSteps.IndexOf (wizardStep);
814 if (i == -1) throw new ArgumentException ("The provided wizard step does not belong to this wizard.");
819 public WizardStepType GetStepType (WizardStepBase wizardStep, int index)
821 if (wizardStep.StepType == WizardStepType.Auto) {
822 if (index == WizardSteps.Count - 1)
823 return WizardStepType.Finish;
825 return WizardStepType.Start;
827 return WizardStepType.Step;
829 return wizardStep.StepType;
833 protected virtual bool AllowNavigationToStep (int index)
835 if (index < 0 || index >= WizardSteps.Count) return false;
836 if (history == null) return true;
837 if (!history.Contains (index)) return true;
838 return WizardSteps [index].AllowReturn;
841 protected internal override void OnInit (EventArgs e)
843 Page.RegisterRequiresControlState (this);
847 protected override ControlCollection CreateControlCollection ()
849 ControlCollection col = new ControlCollection (this);
850 col.SetReadonly (true);
854 protected internal override void CreateChildControls ()
856 CreateControlHierarchy ();
859 protected virtual void CreateControlHierarchy ()
863 wizardTable = new Table ();
864 wizardTable.CellPadding = CellPadding;
865 wizardTable.CellSpacing = CellSpacing;
866 wizardTable.ID = this.ID;
868 AddHeaderRow (wizardTable);
870 TableRow viewRow = new TableRow ();
871 TableCell viewCell = new TableCell ();
873 if (multiView == null)
875 multiView = new MultiView();
876 foreach (View v in WizardSteps) {
877 if (v is TemplatedWizardStep)
878 InstantiateTemplateStep ((TemplatedWizardStep) v);
879 multiView.Views.Add (v);
883 multiView.ActiveViewIndex = activeStepIndex;
885 RegisterApplyStyle (viewCell, StepStyle);
886 viewCell.Controls.Add (multiView);
887 viewRow.Cells.Add (viewCell);
888 viewRow.Height = new Unit ("100%");
889 wizardTable.Rows.Add (viewRow);
891 TableRow buttonRow = new TableRow ();
892 TableCell buttonCell = new TableCell ();
893 buttonCell.HorizontalAlign = HorizontalAlign.Right;
894 CreateButtonBar (buttonCell);
895 buttonRow.Cells.Add (buttonCell);
896 wizardTable.Rows.Add (buttonRow);
898 if (DisplaySideBar && ActiveStep.StepType != WizardStepType.Complete) {
899 Table contentTable = wizardTable;
900 contentTable.Height = new Unit ("100%");
901 contentTable.Width = new Unit ("100%");
903 wizardTable = new Table ();
904 wizardTable.CellPadding = CellPadding;
905 wizardTable.CellSpacing = CellSpacing;
906 TableRow row = new TableRow ();
908 TableCellNamingContainer sideBarCell = new TableCellNamingContainer ();
909 sideBarCell.ControlStyle.Height = Unit.Percentage (100);
910 CreateSideBar (sideBarCell);
911 row.Cells.Add (sideBarCell);
913 TableCell contentCell = new TableCell ();
914 contentCell.Controls.Add (contentTable);
915 contentCell.Height = new Unit ("100%");
916 row.Cells.Add (contentCell);
918 wizardTable.Rows.Add (row);
921 Controls.SetReadonly (false);
922 Controls.Add (wizardTable);
923 Controls.SetReadonly (true);
926 internal virtual void InstantiateTemplateStep(TemplatedWizardStep step)
928 step.InstantiateInContainer ();
930 if (step.CustomNavigationTemplate != null) {
931 WizardStepType stepType = GetStepType (step, ActiveStepIndex);
933 case WizardStepType.Start:
934 startNavigationTemplate = step.CustomNavigationTemplate;
937 case WizardStepType.Step:
938 stepNavigationTemplate = step.CustomNavigationTemplate;
941 case WizardStepType.Finish:
942 finishNavigationTemplate = step.CustomNavigationTemplate;
948 void CreateButtonBar (TableCell buttonBarCell)
950 Table t = new Table ();
953 TableRow row = new TableRow ();
954 RegisterApplyStyle (buttonBarCell, NavigationStyle);
956 WizardStepType stepType = GetStepType (ActiveStep, ActiveStepIndex);
958 case WizardStepType.Start:
959 if (startNavigationTemplate != null) {
960 AddTemplateButtonBar (buttonBarCell, startNavigationTemplate, StartNextButtonID, CancelButtonID);
963 if (AllowNavigationToStep (ActiveStepIndex + 1))
964 AddButtonCell (row, CreateButton (StartNextButtonID, MoveNextCommandName, StartNextButtonType, StartNextButtonText, StartNextButtonImageUrl, StartNextButtonStyle));
965 if (DisplayCancelButton)
966 AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
969 case WizardStepType.Step:
970 if (stepNavigationTemplate != null) {
971 AddTemplateButtonBar (buttonBarCell, stepNavigationTemplate, StepPreviousButtonID, StepNextButtonID, CancelButtonID);
974 if (AllowNavigationToStep (ActiveStepIndex - 1))
975 AddButtonCell (row, CreateButton (StepPreviousButtonID, MovePreviousCommandName, StepPreviousButtonType, StepPreviousButtonText, StepPreviousButtonImageUrl, StepPreviousButtonStyle));
976 if (AllowNavigationToStep (ActiveStepIndex + 1))
977 AddButtonCell (row, CreateButton (StepNextButtonID, MoveNextCommandName, StepNextButtonType, StepNextButtonText, StepNextButtonImageUrl, StepNextButtonStyle));
978 if (DisplayCancelButton)
979 AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
982 case WizardStepType.Finish:
983 if (finishNavigationTemplate != null) {
984 AddTemplateButtonBar (buttonBarCell, finishNavigationTemplate, FinishPreviousButtonID, FinishButtonID, CancelButtonID);
987 if (AllowNavigationToStep (ActiveStepIndex - 1))
988 AddButtonCell (row, CreateButton (FinishPreviousButtonID, MovePreviousCommandName, FinishPreviousButtonType, FinishPreviousButtonText, FinishPreviousButtonImageUrl, FinishPreviousButtonStyle));
989 AddButtonCell (row, CreateButton (FinishButtonID, MoveCompleteCommandName, FinishCompleteButtonType, FinishCompleteButtonText, FinishCompleteButtonImageUrl, FinishCompleteButtonStyle));
990 if (DisplayCancelButton)
991 AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
996 buttonBarCell.Controls.Add (t);
999 internal Control CreateButton (string id, string command, ButtonType type, string text, string image, Style style)
1003 case ButtonType.Button:
1004 b = CreateStandartButton ();
1006 case ButtonType.Image:
1007 b = CreateImageButton (image);
1009 case ButtonType.Link:
1010 b = CreateLinkButton ();
1013 throw new ArgumentOutOfRangeException ("type");
1017 b.EnableTheming = false;
1018 ((IButtonControl) b).CommandName = command;
1019 ((IButtonControl) b).Text = text;
1020 ((IButtonControl) b).ValidationGroup = ID;
1022 RegisterApplyStyle (b, NavigationButtonStyle);
1023 RegisterApplyStyle (b, style);
1027 WebControl CreateStandartButton () {
1028 Button btn = new Button ();
1032 WebControl CreateImageButton (string imageUrl) {
1033 ImageButton img = new ImageButton ();
1034 img.ImageUrl = imageUrl;
1038 WebControl CreateLinkButton () {
1039 LinkButton link = new LinkButton ();
1043 void AddTemplateButtonBar (TableCell cell, ITemplate template, params string[] buttonIds)
1045 template.InstantiateIn (cell);
1047 foreach (string id in buttonIds) {
1048 IButtonControl b = cell.FindControl (id) as IButtonControl;
1049 if (b != null) RegisterCommandEvents (b);
1053 void AddButtonCell (TableRow row, Control control)
1055 TableCell cell = new TableCell ();
1056 cell.HorizontalAlign = HorizontalAlign.Right;
1057 cell.Controls.Add (control);
1058 row.Cells.Add (cell);
1061 void CreateSideBar (TableCell sideBarCell)
1063 RegisterApplyStyle (sideBarCell, SideBarStyle);
1065 if (SkipLinkText != "") {
1066 System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
1067 anchor.HRef = "#" + ClientID + "_SkipLink";
1069 Image img = new Image ();
1070 ClientScriptManager csm = new ClientScriptManager (null);
1071 img.ImageUrl = csm.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif");
1072 img.Attributes.Add ("height", "0");
1073 img.Attributes.Add ("width", "0");
1074 img.AlternateText = SkipLinkText;
1076 anchor.Controls.Add (img);
1077 sideBarCell.Controls.Add (anchor);
1080 if (sideBarTemplate != null) {
1081 sideBarTemplate.InstantiateIn (sideBarCell);
1082 stepDatalist = sideBarCell.FindControl (DataListID) as DataList;
1083 stepDatalist.ItemDataBound += new DataListItemEventHandler(StepDatalistItemDataBound);
1084 if (stepDatalist == null)
1085 throw new InvalidOperationException ("The side bar template must contain a DataList control with id '" + DataListID + "'.");
1087 stepDatalist = new DataList ();
1088 stepDatalist.ID = DataListID;
1089 stepDatalist.ItemTemplate = SideBarItemTemplate;
1090 sideBarCell.Controls.Add (stepDatalist);
1093 if (SkipLinkText != "") {
1094 System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
1095 anchor.ID = "SkipLink";
1096 sideBarCell.Controls.Add (anchor);
1099 stepDatalist.CellSpacing = 0;
1100 stepDatalist.DataSource = WizardSteps;
1101 stepDatalist.DataBind ();
1104 void StepDatalistItemDataBound (object sender, DataListItemEventArgs e)
1106 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
1107 IButtonControl button = (IButtonControl) e.Item.FindControl (SideBarButtonID);
1108 WizardStep step = (WizardStep) e.Item.DataItem;
1110 button.CommandName = Wizard.MoveToCommandName;
1111 button.CommandArgument = WizardSteps.IndexOf (step).ToString ();
1112 button.Text = step.Name;
1116 void AddHeaderRow (Table table)
1118 if (HeaderText.Length != 0 || headerTemplate != null) {
1119 TableRow row = new TableRow ();
1120 TableCell cell = new TableCell ();
1121 RegisterApplyStyle (cell, HeaderStyle);
1122 if (headerTemplate != null)
1123 headerTemplate.InstantiateIn (cell);
1125 cell.Text = HeaderText;
1126 row.Cells.Add (cell);
1127 table.Rows.Add (row);
1131 internal void RegisterApplyStyle (WebControl control, Style style)
1133 styles.Add (new object[] { control, style });
1136 protected override Style CreateControlStyle ()
1138 TableStyle style = new TableStyle ();
1139 style.CellPadding = 0;
1140 style.CellSpacing = 0;
1145 protected override IDictionary GetDesignModeState ()
1147 throw new NotImplementedException ();
1150 protected internal override void LoadControlState (object ob)
1152 if (ob == null) return;
1153 object[] state = (object[]) ob;
1154 base.LoadControlState (state[0]);
1155 activeStepIndex = (int) state[1];
1156 history = (ArrayList) state[2];
1159 protected internal override object SaveControlState ()
1161 object bstate = base.SaveControlState ();
1162 return new object[] {
1163 bstate, activeStepIndex, history
1167 protected override void LoadViewState (object savedState)
1169 if (savedState == null) {
1170 base.LoadViewState (null);
1174 object[] states = (object[]) savedState;
1175 base.LoadViewState (states [0]);
1177 if (states[1] != null) ((IStateManager)StepStyle).LoadViewState (states[1]);
1178 if (states[2] != null) ((IStateManager)SideBarStyle).LoadViewState (states[2]);
1179 if (states[3] != null) ((IStateManager)HeaderStyle).LoadViewState (states[3]);
1180 if (states[4] != null) ((IStateManager)NavigationStyle).LoadViewState (states[4]);
1181 if (states[5] != null) ((IStateManager)SideBarButtonStyle).LoadViewState (states[5]);
1182 if (states[6] != null) ((IStateManager)CancelButtonStyle).LoadViewState (states[6]);
1183 if (states[7] != null) ((IStateManager)FinishCompleteButtonStyle).LoadViewState (states[7]);
1184 if (states[8] != null) ((IStateManager)FinishPreviousButtonStyle).LoadViewState (states[8]);
1185 if (states[9] != null) ((IStateManager)StartNextButtonStyle).LoadViewState (states[9]);
1186 if (states[10] != null) ((IStateManager)StepNextButtonStyle).LoadViewState (states[10]);
1187 if (states[11] != null) ((IStateManager)StepPreviousButtonStyle).LoadViewState (states[11]);
1188 if (states[12] != null) ((IStateManager)NavigationButtonStyle).LoadViewState (states[12]);
1191 protected override object SaveViewState ()
1193 object[] state = new object [13];
1194 state [0] = base.SaveViewState ();
1196 if (stepStyle != null) state [1] = ((IStateManager)stepStyle).SaveViewState ();
1197 if (sideBarStyle != null) state [2] = ((IStateManager)sideBarStyle).SaveViewState ();
1198 if (headerStyle != null) state [3] = ((IStateManager)headerStyle).SaveViewState ();
1199 if (navigationStyle != null) state [4] = ((IStateManager)navigationStyle).SaveViewState ();
1200 if (sideBarButtonStyle != null) state [5] = ((IStateManager)sideBarButtonStyle).SaveViewState ();
1201 if (cancelButtonStyle != null) state [6] = ((IStateManager)cancelButtonStyle).SaveViewState ();
1202 if (finishCompleteButtonStyle != null) state [7] = ((IStateManager)finishCompleteButtonStyle).SaveViewState ();
1203 if (finishPreviousButtonStyle != null) state [8] = ((IStateManager)finishPreviousButtonStyle).SaveViewState ();
1204 if (startNextButtonStyle != null) state [9] = ((IStateManager)startNextButtonStyle).SaveViewState ();
1205 if (stepNextButtonStyle != null) state [10] = ((IStateManager)stepNextButtonStyle).SaveViewState ();
1206 if (stepPreviousButtonStyle != null) state [11] = ((IStateManager)stepPreviousButtonStyle).SaveViewState ();
1207 if (navigationButtonStyle != null) state [12] = ((IStateManager)navigationButtonStyle).SaveViewState ();
1209 for (int n=0; n<state.Length; n++)
1210 if (state [n] != null) return state;
1214 protected override void TrackViewState ()
1216 base.TrackViewState();
1217 if (stepStyle != null) ((IStateManager)stepStyle).TrackViewState();
1218 if (sideBarStyle != null) ((IStateManager)sideBarStyle).TrackViewState();
1219 if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
1220 if (navigationStyle != null) ((IStateManager)navigationStyle).TrackViewState();
1221 if (sideBarButtonStyle != null) ((IStateManager)sideBarButtonStyle).TrackViewState();
1222 if (cancelButtonStyle != null) ((IStateManager)cancelButtonStyle).TrackViewState();
1223 if (finishCompleteButtonStyle != null) ((IStateManager)finishCompleteButtonStyle).TrackViewState();
1224 if (finishPreviousButtonStyle != null) ((IStateManager)finishPreviousButtonStyle).TrackViewState();
1225 if (startNextButtonStyle != null) ((IStateManager)startNextButtonStyle).TrackViewState();
1226 if (stepNextButtonStyle != null) ((IStateManager)stepNextButtonStyle).TrackViewState();
1227 if (stepPreviousButtonStyle != null) ((IStateManager)stepPreviousButtonStyle).TrackViewState();
1228 if (navigationButtonStyle != null) ((IStateManager)navigationButtonStyle).TrackViewState();
1231 protected internal void RegisterCommandEvents (IButtonControl button)
1233 button.Command += ProcessCommand;
1236 void ProcessCommand (object sender, CommandEventArgs args)
1238 Control c = sender as Control;
1241 case "CancelButton":
1242 ProcessEvent ("Cancel", null);
1244 case "FinishButton":
1245 ProcessEvent ("MoveComplete", null);
1247 case "StepPreviousButton":
1248 case "FinishPreviousButton":
1249 ProcessEvent ("MovePrevious", null);
1251 case "StartNextButton":
1252 case "StepNextButton":
1253 ProcessEvent ("MoveNext", null);
1257 ProcessEvent (args.CommandName, args.CommandArgument as string);
1260 protected override bool OnBubbleEvent (object source, EventArgs e)
1262 CommandEventArgs args = e as CommandEventArgs;
1264 ProcessEvent (args.CommandName, args.CommandArgument as string);
1267 return base.OnBubbleEvent (source, e);
1270 void ProcessEvent (string commandName, string commandArg)
1272 switch (commandName) {
1274 if (CancelDestinationPageUrl.Length > 0)
1275 Context.Response.Redirect (CancelDestinationPageUrl);
1277 OnCancelButtonClick (EventArgs.Empty);
1280 case "MoveComplete":
1281 if (FinishDestinationPageUrl.Length > 0) {
1282 Context.Response.Redirect (FinishDestinationPageUrl);
1287 for (int n=0; n<WizardSteps.Count; n++) {
1288 if (WizardSteps [n].StepType == WizardStepType.Complete) {
1294 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, next);
1295 OnFinishButtonClick (args);
1297 ActiveStepIndex = next;
1302 if (ActiveStepIndex < WizardSteps.Count - 1) {
1303 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex + 1);
1304 OnNextButtonClick (args);
1310 case "MovePrevious":
1311 if (ActiveStepIndex > 0) {
1312 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex - 1);
1313 OnPreviousButtonClick (args);
1320 int newb = int.Parse (commandArg);
1321 ActiveStepIndex = newb;
1326 void UpdateControls ()
1328 ChildControlsCreated = false;
1331 internal void UpdateViews ()
1337 protected internal override void Render (HtmlTextWriter writer)
1339 if (multiView.ActiveViewIndex != ActiveStepIndex)
1340 CreateControlHierarchy ();
1342 wizardTable.ApplyStyle (ControlStyle);
1344 foreach (object[] styleDef in styles)
1345 ((WebControl)styleDef[0]).ApplyStyle ((Style)styleDef[1]);
1347 wizardTable.Render (writer);
1350 class TableCellNamingContainer : TableCell, INamingContainer
1354 class SideBarButtonTemplate: ITemplate
1358 public SideBarButtonTemplate (Wizard wizard)
1360 this.wizard = wizard;
1363 public void InstantiateIn (Control control)
1365 LinkButton b = new LinkButton ();
1366 wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1367 control.Controls.Add (b);
1368 control.DataBinding += Bound;
1371 void Bound (object s, EventArgs args)
1373 WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1375 DataListItem c = (DataListItem) s;
1376 LinkButton b = (LinkButton) c.Controls[0];
1377 b.ID = SideBarButtonID;
1378 b.CommandName = Wizard.MoveToCommandName;
1379 b.CommandArgument = wizard.WizardSteps.IndexOf (step).ToString ();
1381 if (step.StepType == WizardStepType.Complete)
1383 if (step == wizard.ActiveStep)
1385 wizard.RegisterCommandEvents (b);