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")]
\r
40 [BindableAttribute (false)]
\r
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";
\r
46 public static readonly string MoveCompleteCommandName = "MoveComplete";
\r
47 public static readonly string MoveNextCommandName = "MoveNext";
\r
48 public static readonly string MovePreviousCommandName = "MovePrevious";
\r
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)]
\r
189 [BrowsableAttribute (false)]
\r
190 public WizardStepBase ActiveStep {
192 if (activeStepIndex < -1 || activeStepIndex >= steps.Count)
193 throw new InvalidOperationException ("ActiveStepIndex has an invalid value.");
194 if (activeStepIndex == -1) return null;
195 return steps [activeStepIndex];
199 [DefaultValueAttribute (-1)]
\r
200 [ThemeableAttribute (false)]
\r
201 public virtual int ActiveStepIndex {
203 return activeStepIndex;
206 if (!AllowNavigationToStep (value))
208 if (activeStepIndex != value) {
209 if (history == null) history = new ArrayList ();
210 history.Insert (0, activeStepIndex);
212 activeStepIndex = value;
214 OnActiveStepChanged (this, EventArgs.Empty);
218 [UrlPropertyAttribute]
\r
219 [DefaultValueAttribute ("")]
\r
220 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
221 public virtual string CancelButtonImageUrl {
223 object v = ViewState ["CancelButtonImageUrl"];
224 return v != null ? (string)v : string.Empty;
227 ViewState ["CancelButtonImageUrl"] = value;
232 [DefaultValueAttribute (null)]
\r
233 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
234 [NotifyParentPropertyAttribute (true)]
\r
235 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
236 public Style CancelButtonStyle {
238 if (cancelButtonStyle == null) {
239 cancelButtonStyle = new Style ();
240 if (IsTrackingViewState)
241 ((IStateManager)cancelButtonStyle).TrackViewState ();
243 return cancelButtonStyle;
247 [LocalizableAttribute (true)]
\r
248 public virtual string CancelButtonText {
250 object v = ViewState ["CancelButtonText"];
251 return v != null ? (string)v : "Cancel";
254 ViewState ["CancelButtonText"] = value;
259 [DefaultValueAttribute (ButtonType.Button)]
\r
260 public virtual ButtonType CancelButtonType {
262 object v = ViewState ["CancelButtonType"];
263 return v != null ? (ButtonType)v : ButtonType.Button;
266 ViewState ["CancelButtonType"] = value;
271 [UrlPropertyAttribute]
\r
272 [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
273 [DefaultValueAttribute ("")]
\r
274 public virtual string CancelDestinationPageUrl {
276 object v = ViewState ["CancelDestinationPageUrl"];
277 return v != null ? (string)v : string.Empty;
280 ViewState ["CancelDestinationPageUrl"] = value;
284 [DefaultValueAttribute (0)]
\r
285 public virtual int CellPadding {
287 object v = ViewState ["CellPadding"];
288 return v != null ? (int)v : 0;
291 ViewState ["CellPadding"] = value;
296 [DefaultValueAttribute (0)]
\r
297 public virtual int CellSpacing {
299 object v = ViewState ["CellSpacing"];
300 return v != null ? (int)v : 0;
303 ViewState ["CellSpacing"] = value;
308 [DefaultValueAttribute (false)]
\r
309 [ThemeableAttribute (false)]
\r
310 public virtual bool DisplayCancelButton {
312 object v = ViewState ["DisplayCancelButton"];
313 return v != null ? (bool) v : false;
316 ViewState ["DisplayCancelButton"] = value;
321 [DefaultValueAttribute (true)]
\r
322 [ThemeableAttribute (false)]
\r
323 public virtual bool DisplaySideBar {
325 object v = ViewState ["DisplaySideBar"];
326 return v != null ? (bool) v : true;
329 ViewState ["DisplaySideBar"] = value;
334 [UrlPropertyAttribute]
\r
335 [DefaultValueAttribute ("")]
\r
336 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
337 public virtual string FinishCompleteButtonImageUrl {
339 object v = ViewState ["FinishCompleteButtonImageUrl"];
340 return v != null ? (string)v : string.Empty;
343 ViewState ["FinishCompleteButtonImageUrl"] = value;
348 [DefaultValueAttribute (null)]
\r
349 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
350 [NotifyParentPropertyAttribute (true)]
\r
351 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
352 public Style FinishCompleteButtonStyle {
354 if (finishCompleteButtonStyle == null) {
355 finishCompleteButtonStyle = new Style ();
356 if (IsTrackingViewState)
357 ((IStateManager)finishCompleteButtonStyle).TrackViewState ();
359 return finishCompleteButtonStyle;
363 [LocalizableAttribute (true)]
\r
364 public virtual string FinishCompleteButtonText {
366 object v = ViewState ["FinishCompleteButtonText"];
367 return v != null ? (string)v : "Finish";
370 ViewState ["FinishCompleteButtonText"] = value;
375 [DefaultValueAttribute (ButtonType.Button)]
\r
376 public virtual ButtonType FinishCompleteButtonType {
378 object v = ViewState ["FinishCompleteButtonType"];
379 return v != null ? (ButtonType)v : ButtonType.Button;
382 ViewState ["FinishCompleteButtonType"] = value;
387 [UrlPropertyAttribute]
\r
388 [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
389 [DefaultValueAttribute ("")]
\r
390 public virtual string FinishDestinationPageUrl {
392 object v = ViewState ["FinishDestinationPageUrl"];
393 return v != null ? (string)v : string.Empty;
396 ViewState ["FinishDestinationPageUrl"] = value;
400 [DefaultValue (null)]
401 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
402 [PersistenceMode (PersistenceMode.InnerProperty)]
404 public virtual ITemplate FinishNavigationTemplate {
405 get { return finishNavigationTemplate; }
406 set { finishNavigationTemplate = value; UpdateControls (); }
409 [UrlPropertyAttribute]
\r
410 [DefaultValueAttribute ("")]
\r
411 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
412 public virtual string FinishPreviousButtonImageUrl {
414 object v = ViewState ["FinishPreviousButtonImageUrl"];
415 return v != null ? (string)v : string.Empty;
418 ViewState ["FinishPreviousButtonImageUrl"] = value;
423 [DefaultValueAttribute (null)]
\r
424 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
425 [NotifyParentPropertyAttribute (true)]
\r
426 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
427 public Style FinishPreviousButtonStyle {
429 if (finishPreviousButtonStyle == null) {
430 finishPreviousButtonStyle = new Style ();
431 if (IsTrackingViewState)
432 ((IStateManager)finishPreviousButtonStyle).TrackViewState ();
434 return finishPreviousButtonStyle;
438 [LocalizableAttribute (true)]
\r
439 public virtual string FinishPreviousButtonText {
441 object v = ViewState ["FinishPreviousButtonText"];
442 return v != null ? (string)v : "Previous";
445 ViewState ["FinishPreviousButtonText"] = value;
450 [DefaultValueAttribute (ButtonType.Button)]
\r
451 public virtual ButtonType FinishPreviousButtonType {
453 object v = ViewState ["FinishPreviousButtonType"];
454 return v != null ? (ButtonType)v : ButtonType.Button;
457 ViewState ["FinishPreviousButtonType"] = value;
462 [DefaultValueAttribute (null)]
\r
463 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
464 [NotifyParentPropertyAttribute (true)]
\r
465 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
466 public TableItemStyle HeaderStyle {
468 if (headerStyle == null) {
469 headerStyle = new TableItemStyle ();
470 if (IsTrackingViewState)
471 ((IStateManager)headerStyle).TrackViewState ();
477 [DefaultValue (null)]
478 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
479 [PersistenceMode (PersistenceMode.InnerProperty)]
481 public virtual ITemplate HeaderTemplate {
482 get { return headerTemplate; }
483 set { headerTemplate = value; UpdateControls (); }
486 [DefaultValueAttribute ("")]
\r
487 [LocalizableAttribute (true)]
\r
488 public virtual string HeaderText {
490 object v = ViewState ["HeaderText"];
491 return v != null ? (string)v : string.Empty;
494 ViewState ["HeaderText"] = value;
499 [DefaultValueAttribute (null)]
\r
500 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
501 [NotifyParentPropertyAttribute (true)]
\r
502 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
503 public Style NavigationButtonStyle {
505 if (navigationButtonStyle == null) {
506 navigationButtonStyle = new Style ();
507 if (IsTrackingViewState)
508 ((IStateManager)navigationButtonStyle).TrackViewState ();
510 return navigationButtonStyle;
514 [DefaultValueAttribute (null)]
\r
515 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
516 [NotifyParentPropertyAttribute (true)]
\r
517 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
518 public TableItemStyle NavigationStyle {
520 if (navigationStyle == null) {
521 navigationStyle = new TableItemStyle ();
522 if (IsTrackingViewState)
523 ((IStateManager)navigationStyle).TrackViewState ();
525 return navigationStyle;
529 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
530 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
531 [DefaultValueAttribute (null)]
\r
532 [NotifyParentPropertyAttribute (true)]
\r
533 public TableItemStyle SideBarStyle {
535 if (sideBarStyle == null) {
536 sideBarStyle = new TableItemStyle ();
537 if (IsTrackingViewState)
538 ((IStateManager)sideBarStyle).TrackViewState ();
544 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
545 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
546 [DefaultValueAttribute (null)]
\r
547 [NotifyParentPropertyAttribute (true)]
\r
548 public Style SideBarButtonStyle {
550 if (sideBarButtonStyle == null) {
551 sideBarButtonStyle = new Style ();
552 if (IsTrackingViewState)
553 ((IStateManager)sideBarButtonStyle).TrackViewState ();
555 return sideBarButtonStyle;
559 [DefaultValue (null)]
560 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
561 [PersistenceMode (PersistenceMode.InnerProperty)]
563 public virtual ITemplate SideBarTemplate {
564 get { return sideBarTemplate; }
565 set { sideBarTemplate = value; UpdateControls (); }
570 public virtual string SkipLinkText
573 throw new NotImplementedException ();
576 throw new NotImplementedException ();
580 [DefaultValue (null)]
581 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
582 [PersistenceMode (PersistenceMode.InnerProperty)]
584 public virtual ITemplate StartNavigationTemplate {
585 get { return startNavigationTemplate; }
586 set { startNavigationTemplate = value; UpdateControls (); }
589 [UrlPropertyAttribute]
\r
590 [DefaultValueAttribute ("")]
\r
591 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
592 public virtual string StartNextButtonImageUrl {
594 object v = ViewState ["StartNextButtonImageUrl"];
595 return v != null ? (string)v : string.Empty;
598 ViewState ["StartNextButtonImageUrl"] = value;
603 [DefaultValueAttribute (null)]
\r
604 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
605 [NotifyParentPropertyAttribute (true)]
\r
606 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
607 public Style StartNextButtonStyle {
609 if (startNextButtonStyle == null) {
610 startNextButtonStyle = new Style ();
611 if (IsTrackingViewState)
612 ((IStateManager)startNextButtonStyle).TrackViewState ();
614 return startNextButtonStyle;
618 [LocalizableAttribute (true)]
\r
619 public virtual string StartNextButtonText {
621 object v = ViewState ["StartNextButtonText"];
622 return v != null ? (string)v : "Next";
625 ViewState ["StartNextButtonText"] = value;
630 [DefaultValueAttribute (ButtonType.Button)]
\r
631 public virtual ButtonType StartNextButtonType {
633 object v = ViewState ["StartNextButtonType"];
634 return v != null ? (ButtonType)v : ButtonType.Button;
637 ViewState ["StartNextButtonType"] = value;
642 [DefaultValue (null)]
643 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
644 [PersistenceMode (PersistenceMode.InnerProperty)]
646 public virtual ITemplate StepNavigationTemplate {
647 get { return stepNavigationTemplate; }
648 set { stepNavigationTemplate = value; UpdateControls (); }
651 [UrlPropertyAttribute]
\r
652 [DefaultValueAttribute ("")]
\r
653 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
654 public virtual string StepNextButtonImageUrl {
656 object v = ViewState ["StepNextButtonImageUrl"];
657 return v != null ? (string)v : string.Empty;
660 ViewState ["StepNextButtonImageUrl"] = value;
665 [DefaultValueAttribute (null)]
\r
666 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
667 [NotifyParentPropertyAttribute (true)]
\r
668 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
669 public Style StepNextButtonStyle {
671 if (stepNextButtonStyle == null) {
672 stepNextButtonStyle = new Style ();
673 if (IsTrackingViewState)
674 ((IStateManager)stepNextButtonStyle).TrackViewState ();
676 return stepNextButtonStyle;
680 [LocalizableAttribute (true)]
\r
681 public virtual string StepNextButtonText {
683 object v = ViewState ["StepNextButtonText"];
684 return v != null ? (string)v : "Next";
687 ViewState ["StepNextButtonText"] = value;
692 [DefaultValueAttribute (ButtonType.Button)]
\r
693 public virtual ButtonType StepNextButtonType {
695 object v = ViewState ["StepNextButtonType"];
696 return v != null ? (ButtonType)v : ButtonType.Button;
699 ViewState ["StepNextButtonType"] = value;
704 [UrlPropertyAttribute]
\r
705 [DefaultValueAttribute ("")]
\r
706 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
707 public virtual string StepPreviousButtonImageUrl {
709 object v = ViewState ["StepPreviousButtonImageUrl"];
710 return v != null ? (string)v : string.Empty;
713 ViewState ["StepPreviousButtonImageUrl"] = value;
718 [DefaultValueAttribute (null)]
\r
719 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
720 [NotifyParentPropertyAttribute (true)]
\r
721 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
722 public Style StepPreviousButtonStyle {
724 if (stepPreviousButtonStyle == null) {
725 stepPreviousButtonStyle = new Style ();
726 if (IsTrackingViewState)
727 ((IStateManager)stepPreviousButtonStyle).TrackViewState ();
729 return stepPreviousButtonStyle;
733 [LocalizableAttribute (true)]
\r
734 public virtual string StepPreviousButtonText {
736 object v = ViewState ["StepPreviousButtonText"];
737 return v != null ? (string)v : "Previous";
740 ViewState ["StepPreviousButtonText"] = value;
745 [DefaultValueAttribute (ButtonType.Button)]
\r
746 public virtual ButtonType StepPreviousButtonType {
748 object v = ViewState ["StepPreviousButtonType"];
749 return v != null ? (ButtonType)v : ButtonType.Button;
752 ViewState ["StepPreviousButtonType"] = value;
757 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
758 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
759 [DefaultValueAttribute (null)]
\r
760 [NotifyParentPropertyAttribute (true)]
\r
761 public TableItemStyle StepStyle {
763 if (stepStyle == null) {
764 stepStyle = new TableItemStyle ();
765 if (IsTrackingViewState)
766 ((IStateManager)stepStyle).TrackViewState ();
772 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
\r
773 [EditorAttribute ("System.Web.UI.Design.WebControls.WizardStepCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
774 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
\r
775 [ThemeableAttribute (false)]
\r
776 public virtual WizardStepCollection WizardSteps {
779 steps = new WizardStepCollection (this);
785 protected virtual new HtmlTextWriterTag TagKey
788 throw new NotImplementedException ();
792 public ICollection GetHistory ()
794 if (history == null) history = new ArrayList ();
798 public void MoveTo (WizardStepBase wizardStep)
800 if (wizardStep == null) throw new ArgumentNullException ("wizardStep");
802 int i = WizardSteps.IndexOf (wizardStep);
803 if (i == -1) throw new ArgumentException ("The provided wizard step does not belong to this wizard.");
808 public WizardStepType GetStepType (WizardStepBase wizardStep, int index)
810 if (wizardStep.StepType == WizardStepType.Auto) {
812 return WizardStepType.Start;
813 else if (index == WizardSteps.Count - 1)
814 return WizardStepType.Finish;
816 return WizardStepType.Step;
818 return wizardStep.StepType;
822 protected virtual bool AllowNavigationToStep (int index)
824 if (index < 0 || index >= WizardSteps.Count) return false;
825 if (history == null) return true;
826 if (!history.Contains (index)) return true;
827 return WizardSteps [index].AllowReturn;
830 protected internal override void OnInit (EventArgs e)
832 Page.RegisterRequiresControlState (this);
836 protected override ControlCollection CreateControlCollection ()
838 ControlCollection col = new ControlCollection (this);
839 col.SetReadonly (true);
843 protected internal override void CreateChildControls ()
845 CreateControlHierarchy ();
848 protected virtual void CreateControlHierarchy ()
852 wizardTable = new Table ();
853 wizardTable.CellPadding = CellPadding;
854 wizardTable.CellSpacing = CellSpacing;
856 AddHeaderRow (wizardTable);
858 TableRow viewRow = new TableRow ();
859 TableCell viewCell = new TableCell ();
861 if (multiView == null) {
862 multiView = new MultiView ();
863 foreach (View v in WizardSteps)
864 multiView.Views.Add (v);
867 multiView.ActiveViewIndex = activeStepIndex;
869 RegisterApplyStyle (viewCell, StepStyle);
870 viewCell.Controls.Add (multiView);
872 viewCell.Height = new Unit ("100%");
873 viewRow.Cells.Add (viewCell);
874 wizardTable.Rows.Add (viewRow);
876 TableRow buttonRow = new TableRow ();
877 TableCell buttonCell = new TableCell ();
878 CreateButtonBar (buttonCell);
879 buttonRow.Cells.Add (buttonCell);
880 wizardTable.Rows.Add (buttonRow);
882 if (DisplaySideBar && ActiveStep.StepType != WizardStepType.Complete) {
883 Table contentTable = wizardTable;
884 contentTable.Height = new Unit ("100%");
886 wizardTable = new Table ();
887 wizardTable.CellPadding = CellPadding;
888 wizardTable.CellSpacing = CellSpacing;
889 TableRow row = new TableRow ();
891 TableCell sideBarCell = new TableCell ();
892 CreateSideBar (sideBarCell);
893 row.Cells.Add (sideBarCell);
895 TableCell contentCell = new TableCell ();
896 contentCell.Controls.Add (contentTable);
897 row.Cells.Add (contentCell);
899 wizardTable.Rows.Add (row);
902 Controls.SetReadonly (false);
903 Controls.Add (wizardTable);
904 Controls.SetReadonly (true);
907 void CreateButtonBar (TableCell buttonBarCell)
909 Table t = new Table ();
910 TableRow row = new TableRow ();
911 RegisterApplyStyle (buttonBarCell, NavigationStyle);
913 WizardStepType stepType = GetStepType (ActiveStep, ActiveStepIndex);
915 case WizardStepType.Start:
916 if (startNavigationTemplate != null) {
917 AddTemplateCell (row, startNavigationTemplate, StartNextButtonID, CancelButtonID);
919 if (DisplayCancelButton)
920 AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
921 if (AllowNavigationToStep (ActiveStepIndex + 1))
922 AddButtonCell (row, CreateButton (StartNextButtonID, MoveNextCommandName, StartNextButtonType, StartNextButtonText, StartNextButtonImageUrl, StartNextButtonStyle));
925 case WizardStepType.Step:
926 if (stepNavigationTemplate != null) {
927 AddTemplateCell (row, stepNavigationTemplate, StepPreviousButtonID, StepNextButtonID, CancelButtonID);
929 if (DisplayCancelButton)
930 AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
931 if (AllowNavigationToStep (ActiveStepIndex - 1))
932 AddButtonCell (row, CreateButton (StepPreviousButtonID, MovePreviousCommandName, StepPreviousButtonType, StepPreviousButtonText, StepPreviousButtonImageUrl, StepPreviousButtonStyle));
933 if (AllowNavigationToStep (ActiveStepIndex + 1))
934 AddButtonCell (row, CreateButton (StepNextButtonID, MoveNextCommandName, StepNextButtonType, StepNextButtonText, StepNextButtonImageUrl, StepNextButtonStyle));
937 case WizardStepType.Finish:
938 if (finishNavigationTemplate != null) {
939 AddTemplateCell (row, finishNavigationTemplate, FinishPreviousButtonID, FinishButtonID, CancelButtonID);
941 if (DisplayCancelButton)
942 AddButtonCell (row, CreateButton (CancelButtonID, CancelCommandName, CancelButtonType, CancelButtonText, CancelButtonImageUrl, CancelButtonStyle));
943 if (AllowNavigationToStep (ActiveStepIndex - 1))
944 AddButtonCell (row, CreateButton (FinishPreviousButtonID, MovePreviousCommandName, FinishPreviousButtonType, FinishPreviousButtonText, FinishPreviousButtonImageUrl, FinishPreviousButtonStyle));
945 AddButtonCell (row, CreateButton (FinishButtonID, MoveCompleteCommandName, FinishCompleteButtonType, FinishCompleteButtonText, FinishCompleteButtonImageUrl, FinishCompleteButtonStyle));
950 buttonBarCell.Controls.Add (t);
953 Control CreateButton (string id, string command, ButtonType type, string text, string image, Style style)
955 DataControlButton b = new DataControlButton (this, text, image, command, "", false);
958 RegisterApplyStyle (b, NavigationButtonStyle);
959 RegisterApplyStyle (b, style);
963 void AddTemplateCell (TableRow row, ITemplate template, params string[] buttonIds)
965 TableCell cell = new TableCell ();
966 template.InstantiateIn (cell);
968 foreach (string id in buttonIds) {
969 IButtonControl b = cell.FindControl (id) as IButtonControl;
970 if (b != null) RegisterCommandEvents (b);
973 row.Cells.Add (cell);
976 void AddButtonCell (TableRow row, Control control)
978 TableCell cell = new TableCell ();
979 cell.Controls.Add (control);
980 row.Cells.Add (cell);
983 void CreateSideBar (TableCell sideBarCell)
985 RegisterApplyStyle (sideBarCell, SideBarStyle);
987 if (sideBarTemplate != null) {
988 sideBarTemplate.InstantiateIn (sideBarCell);
989 stepDatalist = sideBarCell.FindControl (DataListID) as DataList;
990 if (stepDatalist == null)
991 throw new InvalidOperationException ("The side bar template must contain a DataList control with id '" + DataListID + "'.");
993 stepDatalist = new DataList ();
994 stepDatalist.ID = DataListID;
995 sideBarCell.Controls.Add (stepDatalist);
998 stepDatalist.DataSource = WizardSteps;
999 stepDatalist.ItemTemplate = sideBarItemTemplate;
1000 stepDatalist.DataBind ();
1003 void AddHeaderRow (Table table)
1005 if (HeaderText.Length != 0 || headerTemplate != null) {
1006 TableRow row = new TableRow ();
1007 TableCell cell = new TableCell ();
1008 RegisterApplyStyle (cell, HeaderStyle);
1009 if (headerTemplate != null)
1010 headerTemplate.InstantiateIn (cell);
1012 cell.Text = HeaderText;
1013 row.Cells.Add (cell);
1014 table.Rows.Add (row);
1018 internal void RegisterApplyStyle (WebControl control, Style style)
1020 styles.Add (new object[] { control, style });
1023 protected override Style CreateControlStyle ()
1025 return new TableStyle ();
1029 protected override IDictionary GetDesignModeState ()
1031 throw new NotImplementedException ();
1034 protected internal override void LoadControlState (object ob)
1036 if (ob == null) return;
1037 object[] state = (object[]) ob;
1038 base.LoadControlState (state[0]);
1039 activeStepIndex = (int) state[1];
1040 history = (ArrayList) state[2];
1043 protected internal override object SaveControlState ()
1045 object bstate = base.SaveControlState ();
1046 return new object[] {
1047 bstate, activeStepIndex, history
1051 protected override void LoadViewState (object savedState)
1053 if (savedState == null) {
1054 base.LoadViewState (null);
1058 object[] states = (object[]) savedState;
1059 base.LoadViewState (states [0]);
1061 if (states[1] != null) ((IStateManager)StepStyle).LoadViewState (states[1]);
1062 if (states[2] != null) ((IStateManager)SideBarStyle).LoadViewState (states[2]);
1063 if (states[3] != null) ((IStateManager)HeaderStyle).LoadViewState (states[3]);
1064 if (states[4] != null) ((IStateManager)NavigationStyle).LoadViewState (states[4]);
1065 if (states[5] != null) ((IStateManager)SideBarButtonStyle).LoadViewState (states[5]);
1066 if (states[6] != null) ((IStateManager)CancelButtonStyle).LoadViewState (states[6]);
1067 if (states[7] != null) ((IStateManager)FinishCompleteButtonStyle).LoadViewState (states[7]);
1068 if (states[8] != null) ((IStateManager)FinishPreviousButtonStyle).LoadViewState (states[8]);
1069 if (states[9] != null) ((IStateManager)StartNextButtonStyle).LoadViewState (states[9]);
1070 if (states[10] != null) ((IStateManager)StepNextButtonStyle).LoadViewState (states[10]);
1071 if (states[11] != null) ((IStateManager)StepPreviousButtonStyle).LoadViewState (states[11]);
1072 if (states[12] != null) ((IStateManager)NavigationButtonStyle).LoadViewState (states[12]);
1075 protected override object SaveViewState ()
1077 object[] state = new object [13];
1078 state [0] = base.SaveViewState ();
1080 if (stepStyle != null) state [1] = ((IStateManager)stepStyle).SaveViewState ();
1081 if (sideBarStyle != null) state [2] = ((IStateManager)sideBarStyle).SaveViewState ();
1082 if (headerStyle != null) state [3] = ((IStateManager)headerStyle).SaveViewState ();
1083 if (navigationStyle != null) state [4] = ((IStateManager)navigationStyle).SaveViewState ();
1084 if (sideBarButtonStyle != null) state [5] = ((IStateManager)sideBarButtonStyle).SaveViewState ();
1085 if (cancelButtonStyle != null) state [6] = ((IStateManager)cancelButtonStyle).SaveViewState ();
1086 if (finishCompleteButtonStyle != null) state [7] = ((IStateManager)finishCompleteButtonStyle).SaveViewState ();
1087 if (finishPreviousButtonStyle != null) state [8] = ((IStateManager)finishPreviousButtonStyle).SaveViewState ();
1088 if (startNextButtonStyle != null) state [9] = ((IStateManager)startNextButtonStyle).SaveViewState ();
1089 if (stepNextButtonStyle != null) state [10] = ((IStateManager)stepNextButtonStyle).SaveViewState ();
1090 if (stepPreviousButtonStyle != null) state [11] = ((IStateManager)stepPreviousButtonStyle).SaveViewState ();
1091 if (navigationButtonStyle != null) state [12] = ((IStateManager)navigationButtonStyle).SaveViewState ();
1093 for (int n=0; n<state.Length; n++)
1094 if (state [n] != null) return state;
1098 protected override void TrackViewState ()
1100 base.TrackViewState();
1101 if (stepStyle != null) ((IStateManager)stepStyle).TrackViewState();
1102 if (sideBarStyle != null) ((IStateManager)sideBarStyle).TrackViewState();
1103 if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
1104 if (navigationStyle != null) ((IStateManager)navigationStyle).TrackViewState();
1105 if (sideBarButtonStyle != null) ((IStateManager)sideBarButtonStyle).TrackViewState();
1106 if (cancelButtonStyle != null) ((IStateManager)cancelButtonStyle).TrackViewState();
1107 if (finishCompleteButtonStyle != null) ((IStateManager)finishCompleteButtonStyle).TrackViewState();
1108 if (finishPreviousButtonStyle != null) ((IStateManager)finishPreviousButtonStyle).TrackViewState();
1109 if (startNextButtonStyle != null) ((IStateManager)startNextButtonStyle).TrackViewState();
1110 if (stepNextButtonStyle != null) ((IStateManager)stepNextButtonStyle).TrackViewState();
1111 if (stepPreviousButtonStyle != null) ((IStateManager)stepPreviousButtonStyle).TrackViewState();
1112 if (navigationButtonStyle != null) ((IStateManager)navigationButtonStyle).TrackViewState();
1115 protected internal void RegisterCommandEvents (IButtonControl button)
1117 button.Command += ProcessCommand;
1120 void ProcessCommand (object sender, CommandEventArgs args)
1122 Control c = sender as Control;
1125 case "CancelButton":
1126 ProcessEvent ("Cancel", null);
1128 case "FinishButton":
1129 ProcessEvent ("MoveComplete", null);
1131 case "StepPreviousButton":
1132 case "FinishPreviousButton":
1133 ProcessEvent ("MovePrevious", null);
1135 case "StartNextButton":
1136 case "StepNextButton":
1137 ProcessEvent ("MoveNext", null);
1141 ProcessEvent (args.CommandName, args.CommandArgument as string);
1144 protected override bool OnBubbleEvent (object source, EventArgs e)
1146 CommandEventArgs args = e as CommandEventArgs;
1148 ProcessEvent (args.CommandName, args.CommandArgument as string);
1150 return base.OnBubbleEvent (source, e);
1153 void ProcessEvent (string commandName, string commandArg)
1155 switch (commandName) {
1157 if (CancelDestinationPageUrl.Length > 0)
1158 Context.Response.Redirect (CancelDestinationPageUrl);
1160 OnCancelButtonClick (EventArgs.Empty);
1163 case "MoveComplete":
1164 if (FinishDestinationPageUrl.Length > 0) {
1165 Context.Response.Redirect (FinishDestinationPageUrl);
1170 for (int n=0; n<WizardSteps.Count; n++) {
1171 if (WizardSteps [n].StepType == WizardStepType.Complete) {
1177 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, next);
1178 OnFinishButtonClick (args);
1180 ActiveStepIndex = next;
1185 if (ActiveStepIndex < WizardSteps.Count - 1) {
\r
1186 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex + 1);
1187 OnNextButtonClick (args);
1193 case "MovePrevious":
\r
1194 if (ActiveStepIndex > 0) {
\r
1195 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex - 1);
1196 OnPreviousButtonClick (args);
1203 int newb = int.Parse (commandArg);
1204 ActiveStepIndex = newb;
1209 void UpdateControls ()
1211 ChildControlsCreated = false;
1214 internal void UpdateViews ()
1220 protected internal override void Render (HtmlTextWriter writer)
1222 wizardTable.ApplyStyle (ControlStyle);
1224 foreach (object[] styleDef in styles)
1225 ((WebControl)styleDef[0]).ApplyStyle ((Style)styleDef[1]);
1227 wizardTable.Render (writer);
1230 class SideBarButtonTemplate: ITemplate
1234 public SideBarButtonTemplate (Wizard wizard)
1236 this.wizard = wizard;
1239 public void InstantiateIn (Control control)
1241 LinkButton b = new LinkButton ();
1242 wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1243 control.Controls.Add (b);
1244 control.DataBinding += Bound;
1247 void Bound (object s, EventArgs args)
1249 WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1251 Control c = (Control)s;
1252 LinkButton b = (LinkButton) c.Controls[0];
1253 b.ID = SideBarButtonID;
1254 b.CommandName = Wizard.MoveToCommandName;
1255 b.CommandArgument = wizard.WizardSteps.IndexOf (step).ToString ();
1256 b.Text = step.Title;
1257 if (step.StepType == WizardStepType.Complete)
1259 if (step == wizard.ActiveStep)
1261 wizard.RegisterCommandEvents (b);