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.Collections.Generic;
36 using System.ComponentModel;
39 namespace System.Web.UI.WebControls
41 [DefaultEventAttribute ("FinishButtonClick")]
42 [BindableAttribute (false)]
43 [DesignerAttribute ("System.Web.UI.Design.WebControls.WizardDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
44 [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>")]
45 public class Wizard: CompositeControl
47 public static readonly string CancelCommandName = "Cancel";
48 public static readonly string MoveCompleteCommandName = "MoveComplete";
49 public static readonly string MoveNextCommandName = "MoveNext";
50 public static readonly string MovePreviousCommandName = "MovePrevious";
51 public static readonly string MoveToCommandName = "Move";
53 public static readonly string HeaderPlaceholderId = "headerPlaceholder";
54 public static readonly string NavigationPlaceholderId = "navigationPlaceholder";
55 public static readonly string SideBarPlaceholderId = "sideBarPlaceholder";
56 public static readonly string WizardStepPlaceholderId = "wizardStepPlaceholder";
58 protected static readonly string DataListID = "SideBarList";
60 static readonly string CancelButtonIDShort = "Cancel";
61 protected static readonly string CancelButtonID = CancelButtonIDShort + "Button";
63 static readonly string CustomFinishButtonIDShort = "CustomFinish";
64 protected static readonly string CustomFinishButtonID = CustomFinishButtonIDShort + "Button";
66 static readonly string CustomNextButtonIDShort = "CustomNext";
67 protected static readonly string CustomNextButtonID = CustomNextButtonIDShort + "Button";
69 static readonly string CustomPreviousButtonIDShort = "CustomPrevious";
70 protected static readonly string CustomPreviousButtonID = CustomPreviousButtonIDShort + "Button";
72 static readonly string FinishButtonIDShort = "Finish";
73 protected static readonly string FinishButtonID = FinishButtonIDShort + "Button";
75 static readonly string FinishPreviousButtonIDShort = "FinishPrevious";
76 protected static readonly string FinishPreviousButtonID = FinishPreviousButtonIDShort + "Button";
78 static readonly string SideBarButtonIDShort = "SideBar";
79 protected static readonly string SideBarButtonID = SideBarButtonIDShort + "Button";
81 static readonly string StartNextButtonIDShort = "StartNext";
82 protected static readonly string StartNextButtonID = StartNextButtonIDShort + "Button";
84 static readonly string StepNextButtonIDShort = "StepNext";
85 protected static readonly string StepNextButtonID = StepNextButtonIDShort + "Button";
87 static readonly string StepPreviousButtonIDShort = "StepPrevious";
88 protected static readonly string StepPreviousButtonID = StepPreviousButtonIDShort + "Button";
90 WizardStepCollection steps;
94 TableItemStyle stepStyle;
95 TableItemStyle sideBarStyle;
96 TableItemStyle headerStyle;
97 TableItemStyle navigationStyle;
98 Style sideBarButtonStyle;
100 Style cancelButtonStyle;
101 Style finishCompleteButtonStyle;
102 Style finishPreviousButtonStyle;
103 Style startNextButtonStyle;
104 Style stepNextButtonStyle;
105 Style stepPreviousButtonStyle;
106 Style navigationButtonStyle;
108 ITemplate finishNavigationTemplate;
109 ITemplate startNavigationTemplate;
110 ITemplate stepNavigationTemplate;
111 ITemplate headerTemplate;
112 ITemplate sideBarTemplate;
116 int activeStepIndex = -1;
121 WizardHeaderCell _headerCell;
122 TableCell _navigationCell;
123 StartNavigationContainer _startNavContainer;
124 StepNavigationContainer _stepNavContainer;
125 FinishNavigationContainer _finishNavContainer;
127 DataList stepDatalist;
128 ArrayList styles = new ArrayList ();
129 Hashtable customNavigation;
131 static readonly object ActiveStepChangedEvent = new object();
132 static readonly object CancelButtonClickEvent = new object();
133 static readonly object FinishButtonClickEvent = new object();
134 static readonly object NextButtonClickEvent = new object();
135 static readonly object PreviousButtonClickEvent = new object();
136 static readonly object SideBarButtonClickEvent = new object();
138 public event EventHandler ActiveStepChanged {
139 add { Events.AddHandler (ActiveStepChangedEvent, value); }
140 remove { Events.RemoveHandler (ActiveStepChangedEvent, value); }
143 public event EventHandler CancelButtonClick {
144 add { Events.AddHandler (CancelButtonClickEvent, value); }
145 remove { Events.RemoveHandler (CancelButtonClickEvent, value); }
148 public event WizardNavigationEventHandler FinishButtonClick {
149 add { Events.AddHandler (FinishButtonClickEvent, value); }
150 remove { Events.RemoveHandler (FinishButtonClickEvent, value); }
153 public event WizardNavigationEventHandler NextButtonClick {
154 add { Events.AddHandler (NextButtonClickEvent, value); }
155 remove { Events.RemoveHandler (NextButtonClickEvent, value); }
158 public event WizardNavigationEventHandler PreviousButtonClick {
159 add { Events.AddHandler (PreviousButtonClickEvent, value); }
160 remove { Events.RemoveHandler (PreviousButtonClickEvent, value); }
163 public event WizardNavigationEventHandler SideBarButtonClick {
164 add { Events.AddHandler (SideBarButtonClickEvent, value); }
165 remove { Events.RemoveHandler (SideBarButtonClickEvent, value); }
168 protected virtual void OnActiveStepChanged (object source, EventArgs e)
170 if (Events != null) {
171 EventHandler eh = (EventHandler) Events [ActiveStepChangedEvent];
172 if (eh != null) eh (source, e);
176 protected virtual void OnCancelButtonClick (EventArgs e)
178 if (Events != null) {
179 EventHandler eh = (EventHandler) Events [CancelButtonClickEvent];
180 if (eh != null) eh (this, e);
184 protected virtual void OnFinishButtonClick (WizardNavigationEventArgs e)
186 if (Events != null) {
187 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [FinishButtonClickEvent];
188 if (eh != null) eh (this, e);
192 protected virtual void OnNextButtonClick (WizardNavigationEventArgs e)
194 if (Events != null) {
195 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [NextButtonClickEvent];
196 if (eh != null) eh (this, e);
200 protected virtual void OnPreviousButtonClick (WizardNavigationEventArgs e)
202 if (Events != null) {
203 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [PreviousButtonClickEvent];
204 if (eh != null) eh (this, e);
208 protected virtual void OnSideBarButtonClick (WizardNavigationEventArgs e)
210 if (Events != null) {
211 WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [SideBarButtonClickEvent];
212 if (eh != null) eh (this, e);
216 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
217 [BrowsableAttribute (false)]
218 public WizardStepBase ActiveStep {
220 int activeIndex = ActiveStepIndex;
221 if (activeIndex < -1 || activeIndex >= WizardSteps.Count)
222 throw new InvalidOperationException ("ActiveStepIndex has an invalid value.");
223 if (activeIndex == -1)
225 return WizardSteps [activeIndex];
229 [DefaultValueAttribute (-1)]
230 [ThemeableAttribute (false)]
231 public virtual int ActiveStepIndex {
233 return activeStepIndex;
236 if (value < -1 || (value > WizardSteps.Count && (inited || WizardSteps.Count > 0)))
237 throw new ArgumentOutOfRangeException ("The ActiveStepIndex must be less than WizardSteps.Count and at least -1");
238 if (inited && !AllowNavigationToStep (value))
241 if(activeStepIndex != value) {
242 activeStepIndex = value;
245 multiView.ActiveViewIndex = value;
246 if (stepDatalist != null) {
247 stepDatalist.SelectedIndex = value;
248 stepDatalist.DataBind ();
250 OnActiveStepChanged (this, EventArgs.Empty);
256 [UrlPropertyAttribute]
257 [DefaultValueAttribute ("")]
258 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
259 public virtual string CancelButtonImageUrl {
261 object v = ViewState ["CancelButtonImageUrl"];
262 return v != null ? (string)v : string.Empty;
265 ViewState ["CancelButtonImageUrl"] = value;
269 [DefaultValueAttribute (null)]
270 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
271 [NotifyParentPropertyAttribute (true)]
272 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
273 public Style CancelButtonStyle {
275 if (cancelButtonStyle == null) {
276 cancelButtonStyle = new Style ();
277 if (IsTrackingViewState)
278 ((IStateManager)cancelButtonStyle).TrackViewState ();
280 return cancelButtonStyle;
284 [LocalizableAttribute (true)]
285 public virtual string CancelButtonText {
287 object v = ViewState ["CancelButtonText"];
288 return v != null ? (string)v : "Cancel";
291 ViewState ["CancelButtonText"] = value;
295 [DefaultValueAttribute (ButtonType.Button)]
296 public virtual ButtonType CancelButtonType {
298 object v = ViewState ["CancelButtonType"];
299 return v != null ? (ButtonType)v : ButtonType.Button;
302 ViewState ["CancelButtonType"] = value;
306 [UrlPropertyAttribute]
307 [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
308 [DefaultValueAttribute ("")]
310 public virtual string CancelDestinationPageUrl {
312 object v = ViewState ["CancelDestinationPageUrl"];
313 return v != null ? (string)v : string.Empty;
316 ViewState ["CancelDestinationPageUrl"] = value;
320 [DefaultValueAttribute (0)]
321 public virtual int CellPadding {
323 if (ControlStyleCreated)
324 return ((TableStyle) ControlStyle).CellPadding;
328 ((TableStyle) ControlStyle).CellPadding = value;
332 [DefaultValueAttribute (0)]
333 public virtual int CellSpacing {
335 if (ControlStyleCreated)
336 return ((TableStyle) ControlStyle).CellSpacing;
340 ((TableStyle) ControlStyle).CellSpacing = value;
344 [DefaultValueAttribute (false)]
345 [ThemeableAttribute (false)]
346 public virtual bool DisplayCancelButton {
348 object v = ViewState ["DisplayCancelButton"];
349 return v != null ? (bool) v : false;
352 ViewState ["DisplayCancelButton"] = value;
356 [DefaultValueAttribute (true)]
357 [ThemeableAttribute (false)]
358 public virtual bool DisplaySideBar {
360 object v = ViewState ["DisplaySideBar"];
361 return v != null ? (bool) v : true;
364 ViewState ["DisplaySideBar"] = value;
369 [UrlPropertyAttribute]
370 [DefaultValueAttribute ("")]
371 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
372 public virtual string FinishCompleteButtonImageUrl {
374 object v = ViewState ["FinishCompleteButtonImageUrl"];
375 return v != null ? (string)v : string.Empty;
378 ViewState ["FinishCompleteButtonImageUrl"] = value;
382 [DefaultValueAttribute (null)]
383 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
384 [NotifyParentPropertyAttribute (true)]
385 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
386 public Style FinishCompleteButtonStyle {
388 if (finishCompleteButtonStyle == null) {
389 finishCompleteButtonStyle = new Style ();
390 if (IsTrackingViewState)
391 ((IStateManager)finishCompleteButtonStyle).TrackViewState ();
393 return finishCompleteButtonStyle;
397 [LocalizableAttribute (true)]
398 public virtual string FinishCompleteButtonText {
400 object v = ViewState ["FinishCompleteButtonText"];
401 return v != null ? (string)v : "Finish";
404 ViewState ["FinishCompleteButtonText"] = value;
408 [DefaultValueAttribute (ButtonType.Button)]
409 public virtual ButtonType FinishCompleteButtonType {
411 object v = ViewState ["FinishCompleteButtonType"];
412 return v != null ? (ButtonType)v : ButtonType.Button;
415 ViewState ["FinishCompleteButtonType"] = value;
419 [UrlPropertyAttribute]
420 [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
421 [DefaultValueAttribute ("")]
423 public virtual string FinishDestinationPageUrl {
425 object v = ViewState ["FinishDestinationPageUrl"];
426 return v != null ? (string)v : string.Empty;
429 ViewState ["FinishDestinationPageUrl"] = value;
433 [DefaultValue (null)]
434 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
435 [PersistenceMode (PersistenceMode.InnerProperty)]
437 public virtual ITemplate FinishNavigationTemplate {
438 get { return finishNavigationTemplate; }
439 set { finishNavigationTemplate = value; UpdateViews (); }
442 [UrlPropertyAttribute]
443 [DefaultValueAttribute ("")]
444 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
445 public virtual string FinishPreviousButtonImageUrl {
447 object v = ViewState ["FinishPreviousButtonImageUrl"];
448 return v != null ? (string)v : string.Empty;
451 ViewState ["FinishPreviousButtonImageUrl"] = value;
455 [DefaultValueAttribute (null)]
456 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
457 [NotifyParentPropertyAttribute (true)]
458 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
459 public Style FinishPreviousButtonStyle {
461 if (finishPreviousButtonStyle == null) {
462 finishPreviousButtonStyle = new Style ();
463 if (IsTrackingViewState)
464 ((IStateManager)finishPreviousButtonStyle).TrackViewState ();
466 return finishPreviousButtonStyle;
470 [LocalizableAttribute (true)]
471 public virtual string FinishPreviousButtonText {
473 object v = ViewState ["FinishPreviousButtonText"];
474 return v != null ? (string)v : "Previous";
477 ViewState ["FinishPreviousButtonText"] = value;
481 [DefaultValueAttribute (ButtonType.Button)]
482 public virtual ButtonType FinishPreviousButtonType {
484 object v = ViewState ["FinishPreviousButtonType"];
485 return v != null ? (ButtonType)v : ButtonType.Button;
488 ViewState ["FinishPreviousButtonType"] = value;
492 [DefaultValueAttribute (null)]
493 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
494 [NotifyParentPropertyAttribute (true)]
495 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
496 public TableItemStyle HeaderStyle {
498 if (headerStyle == null) {
499 headerStyle = new TableItemStyle ();
500 if (IsTrackingViewState)
501 ((IStateManager)headerStyle).TrackViewState ();
507 [DefaultValue (null)]
508 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
509 [PersistenceMode (PersistenceMode.InnerProperty)]
511 public virtual ITemplate HeaderTemplate {
512 get { return headerTemplate; }
513 set { headerTemplate = value; UpdateViews (); }
516 [DefaultValueAttribute ("")]
517 [LocalizableAttribute (true)]
518 public virtual string HeaderText {
520 object v = ViewState ["HeaderText"];
521 return v != null ? (string)v : string.Empty;
524 ViewState ["HeaderText"] = value;
528 [DefaultValue (null)]
529 [TemplateContainerAttribute(typeof(Wizard))]
530 [PersistenceModeAttribute(PersistenceMode.InnerProperty)]
531 [BrowsableAttribute(false)]
532 public virtual ITemplate LayoutTemplate { get; set; }
534 [DefaultValueAttribute (null)]
535 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
536 [NotifyParentPropertyAttribute (true)]
537 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
538 public Style NavigationButtonStyle {
540 if (navigationButtonStyle == null) {
541 navigationButtonStyle = new Style ();
542 if (IsTrackingViewState)
543 ((IStateManager)navigationButtonStyle).TrackViewState ();
545 return navigationButtonStyle;
549 [DefaultValueAttribute (null)]
550 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
551 [NotifyParentPropertyAttribute (true)]
552 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
553 public TableItemStyle NavigationStyle {
555 if (navigationStyle == null) {
556 navigationStyle = new TableItemStyle ();
557 if (IsTrackingViewState)
558 ((IStateManager)navigationStyle).TrackViewState ();
560 return navigationStyle;
564 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
565 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
566 [DefaultValueAttribute (null)]
567 [NotifyParentPropertyAttribute (true)]
568 public TableItemStyle SideBarStyle {
570 if (sideBarStyle == null) {
571 sideBarStyle = new TableItemStyle ();
572 if (IsTrackingViewState)
573 ((IStateManager)sideBarStyle).TrackViewState ();
579 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
580 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
581 [DefaultValueAttribute (null)]
582 [NotifyParentPropertyAttribute (true)]
583 public Style SideBarButtonStyle {
585 if (sideBarButtonStyle == null) {
586 sideBarButtonStyle = new Style ();
587 if (IsTrackingViewState)
588 ((IStateManager)sideBarButtonStyle).TrackViewState ();
590 return sideBarButtonStyle;
594 [DefaultValue (null)]
595 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
596 [PersistenceMode (PersistenceMode.InnerProperty)]
598 public virtual ITemplate SideBarTemplate {
599 get { return sideBarTemplate; }
600 set { sideBarTemplate = value; UpdateViews (); }
604 public virtual string SkipLinkText
608 object v = ViewState ["SkipLinkText"];
609 return v != null ? (string) v : "Skip Navigation Links.";
613 ViewState ["SkipLinkText"] = value;
617 [DefaultValue (null)]
618 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
619 [PersistenceMode (PersistenceMode.InnerProperty)]
621 public virtual ITemplate StartNavigationTemplate {
622 get { return startNavigationTemplate; }
623 set { startNavigationTemplate = value; UpdateViews (); }
626 [UrlPropertyAttribute]
627 [DefaultValueAttribute ("")]
628 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
629 public virtual string StartNextButtonImageUrl {
631 object v = ViewState ["StartNextButtonImageUrl"];
632 return v != null ? (string)v : string.Empty;
635 ViewState ["StartNextButtonImageUrl"] = value;
639 [DefaultValueAttribute (null)]
640 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
641 [NotifyParentPropertyAttribute (true)]
642 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
643 public Style StartNextButtonStyle {
645 if (startNextButtonStyle == null) {
646 startNextButtonStyle = new Style ();
647 if (IsTrackingViewState)
648 ((IStateManager)startNextButtonStyle).TrackViewState ();
650 return startNextButtonStyle;
654 [LocalizableAttribute (true)]
655 public virtual string StartNextButtonText {
657 object v = ViewState ["StartNextButtonText"];
658 return v != null ? (string)v : "Next";
661 ViewState ["StartNextButtonText"] = value;
665 [DefaultValueAttribute (ButtonType.Button)]
666 public virtual ButtonType StartNextButtonType {
668 object v = ViewState ["StartNextButtonType"];
669 return v != null ? (ButtonType)v : ButtonType.Button;
672 ViewState ["StartNextButtonType"] = value;
676 [DefaultValue (null)]
677 [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
678 [PersistenceMode (PersistenceMode.InnerProperty)]
680 public virtual ITemplate StepNavigationTemplate {
681 get { return stepNavigationTemplate; }
682 set { stepNavigationTemplate = value; UpdateViews (); }
685 [UrlPropertyAttribute]
686 [DefaultValueAttribute ("")]
687 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
688 public virtual string StepNextButtonImageUrl {
690 object v = ViewState ["StepNextButtonImageUrl"];
691 return v != null ? (string)v : string.Empty;
694 ViewState ["StepNextButtonImageUrl"] = value;
698 [DefaultValueAttribute (null)]
699 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
700 [NotifyParentPropertyAttribute (true)]
701 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
702 public Style StepNextButtonStyle {
704 if (stepNextButtonStyle == null) {
705 stepNextButtonStyle = new Style ();
706 if (IsTrackingViewState)
707 ((IStateManager)stepNextButtonStyle).TrackViewState ();
709 return stepNextButtonStyle;
713 [LocalizableAttribute (true)]
714 public virtual string StepNextButtonText {
716 object v = ViewState ["StepNextButtonText"];
717 return v != null ? (string)v : "Next";
720 ViewState ["StepNextButtonText"] = value;
724 [DefaultValueAttribute (ButtonType.Button)]
725 public virtual ButtonType StepNextButtonType {
727 object v = ViewState ["StepNextButtonType"];
728 return v != null ? (ButtonType)v : ButtonType.Button;
731 ViewState ["StepNextButtonType"] = value;
735 [UrlPropertyAttribute]
736 [DefaultValueAttribute ("")]
737 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
738 public virtual string StepPreviousButtonImageUrl {
740 object v = ViewState ["StepPreviousButtonImageUrl"];
741 return v != null ? (string)v : string.Empty;
744 ViewState ["StepPreviousButtonImageUrl"] = value;
748 [DefaultValueAttribute (null)]
749 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
750 [NotifyParentPropertyAttribute (true)]
751 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
752 public Style StepPreviousButtonStyle {
754 if (stepPreviousButtonStyle == null) {
755 stepPreviousButtonStyle = new Style ();
756 if (IsTrackingViewState)
757 ((IStateManager)stepPreviousButtonStyle).TrackViewState ();
759 return stepPreviousButtonStyle;
763 [LocalizableAttribute (true)]
764 public virtual string StepPreviousButtonText {
766 object v = ViewState ["StepPreviousButtonText"];
767 return v != null ? (string)v : "Previous";
770 ViewState ["StepPreviousButtonText"] = value;
774 [DefaultValueAttribute (ButtonType.Button)]
775 public virtual ButtonType StepPreviousButtonType {
777 object v = ViewState ["StepPreviousButtonType"];
778 return v != null ? (ButtonType)v : ButtonType.Button;
781 ViewState ["StepPreviousButtonType"] = value;
785 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
786 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
787 [DefaultValueAttribute (null)]
788 [NotifyParentPropertyAttribute (true)]
789 public TableItemStyle StepStyle {
791 if (stepStyle == null) {
792 stepStyle = new TableItemStyle ();
793 if (IsTrackingViewState)
794 ((IStateManager)stepStyle).TrackViewState ();
800 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
801 [EditorAttribute ("System.Web.UI.Design.WebControls.WizardStepCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
802 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
803 [ThemeableAttribute (false)]
804 public virtual WizardStepCollection WizardSteps {
807 steps = new WizardStepCollection (this);
812 protected virtual new HtmlTextWriterTag TagKey
815 return HtmlTextWriterTag.Table;
819 internal virtual ITemplate SideBarItemTemplate
821 get { return new SideBarButtonTemplate (this); }
824 public ICollection GetHistory ()
827 history = new ArrayList ();
831 public void MoveTo (WizardStepBase wizardStep)
833 if (wizardStep == null)
834 throw new ArgumentNullException ("wizardStep");
836 int i = WizardSteps.IndexOf (wizardStep);
838 throw new ArgumentException ("The provided wizard step does not belong to this wizard.");
843 public WizardStepType GetStepType (WizardStepBase wizardStep, int index)
845 if (wizardStep.StepType == WizardStepType.Auto) {
846 if ((index == WizardSteps.Count - 1) ||
847 (WizardSteps.Count > 1 &&
848 WizardSteps[WizardSteps.Count - 1].StepType == WizardStepType.Complete &&
849 index == WizardSteps.Count - 2))
850 return WizardStepType.Finish;
852 return WizardStepType.Start;
854 return WizardStepType.Step;
856 return wizardStep.StepType;
860 protected virtual bool AllowNavigationToStep (int index)
862 if ((index < 0 || index >= WizardSteps.Count) || history == null || !history.Contains (index))
865 return WizardSteps [index].AllowReturn;
868 protected internal override void OnInit (EventArgs e)
870 Page.RegisterRequiresControlState (this);
873 if (ActiveStepIndex == -1)
876 EnsureChildControls ();
881 protected override ControlCollection CreateControlCollection ()
883 ControlCollection col = new ControlCollection (this);
884 col.SetReadonly (true);
888 protected internal override void CreateChildControls ()
890 CreateControlHierarchy ();
893 InvalidOperationException MakeLayoutException (string phName, string phID, string condition = null)
895 return new InvalidOperationException (
896 String.Format ("A {0} placeholder must be specified on Wizard '{1}'{2}. Specify a placeholder by setting a control's ID property to \"{3}\". The placeholder control must also specify runat=\"server\"",
897 phName, ID, condition, phID)
901 void CreateControlHierarchy_LayoutTemplate (ITemplate layoutTemplate)
903 var layoutContainer = new WizardLayoutContainer ();
904 ControlCollection controls = Controls;
906 controls.SetReadonly (false);
907 controls.Add (layoutContainer);
908 controls.SetReadonly (true);
910 layoutTemplate.InstantiateIn (layoutContainer);
912 WizardStepCollection steps = WizardSteps;
913 bool doRender = steps != null && steps.Count > 0;
914 Control container, placeHolder;
916 if (DisplaySideBar) {
917 placeHolder = layoutContainer.FindControl (SideBarPlaceholderId);
918 if (placeHolder == null)
919 throw MakeLayoutException ("sidebar", SideBarPlaceholderId, " when DisplaySideBar is set to true");
921 container = new Control ();
922 CreateSideBar (container);
923 ReplacePlaceHolder (layoutContainer, placeHolder, container);
926 ITemplate headerTemplate = HeaderTemplate;
927 if (headerTemplate != null) {
928 placeHolder = layoutContainer.FindControl (HeaderPlaceholderId);
929 if (placeHolder == null)
930 throw MakeLayoutException ("header", HeaderPlaceholderId, " when HeaderTemplate is set");
932 container = new Control ();
933 headerTemplate.InstantiateIn (container);
934 ReplacePlaceHolder (layoutContainer, placeHolder, container);
937 placeHolder = layoutContainer.FindControl (WizardStepPlaceholderId);
938 if (placeHolder == null)
939 throw MakeLayoutException ("step", WizardStepPlaceholderId);
941 customNavigation = null;
942 multiView = new MultiView ();
943 foreach (View v in steps) {
944 if (v is TemplatedWizardStep)
945 InstantiateTemplateStep ((TemplatedWizardStep) v);
946 multiView.Views.Add (v);
948 multiView.ActiveViewIndex = ActiveStepIndex;
949 ReplacePlaceHolder (layoutContainer, placeHolder, multiView);
951 placeHolder = layoutContainer.FindControl (NavigationPlaceholderId);
952 if (placeHolder == null)
953 throw MakeLayoutException ("navigation", NavigationPlaceholderId);
956 var contentTable = new Table ();
957 contentTable.CellSpacing = 5;
958 contentTable.CellPadding = 5;
959 var row = new TableRow ();
960 var cell = new TableCell ();
961 cell.HorizontalAlign = HorizontalAlign.Right;
963 container = new Control ();
964 CreateButtonBar (container);
966 row.Cells.Add (cell);
967 contentTable.Rows.Add (row);
968 ReplacePlaceHolder (layoutContainer, placeHolder, container);
970 layoutContainer.Visible = doRender;
973 void ReplacePlaceHolder (WebControl container, Control placeHolder, Control replacement)
975 ControlCollection controls = container.Controls;
976 int index = controls.IndexOf (placeHolder);
977 controls.Remove (placeHolder);
978 controls.AddAt (index, replacement);
981 protected virtual void CreateControlHierarchy ()
984 ITemplate layoutTemplate = LayoutTemplate;
985 if (layoutTemplate != null) {
986 CreateControlHierarchy_LayoutTemplate (layoutTemplate);
992 wizardTable = new ContainedTable (this);
994 Table contentTable = wizardTable;
996 if (DisplaySideBar) {
997 contentTable = new Table ();
998 contentTable.CellPadding = 0;
999 contentTable.CellSpacing = 0;
1000 contentTable.Height = new Unit ("100%");
1001 contentTable.Width = new Unit ("100%");
1003 TableRow row = new TableRow ();
1005 TableCellNamingContainer sideBarCell = new TableCellNamingContainer (SkipLinkText, ClientID);
1006 sideBarCell.ID = "SideBarContainer";
1007 sideBarCell.ControlStyle.Height = Unit.Percentage (100);
1008 CreateSideBar (sideBarCell);
1009 row.Cells.Add (sideBarCell);
1011 TableCell contentCell = new TableCell ();
1012 contentCell.Controls.Add (contentTable);
1013 contentCell.Height = new Unit ("100%");
1014 row.Cells.Add (contentCell);
1016 wizardTable.Rows.Add (row);
1019 AddHeaderRow (contentTable);
1021 TableRow viewRow = new TableRow ();
1022 TableCell viewCell = new TableCell ();
1024 customNavigation = null;
1025 multiView = new MultiView ();
1026 foreach (View v in WizardSteps) {
1027 if (v is TemplatedWizardStep)
1028 InstantiateTemplateStep ((TemplatedWizardStep) v);
1029 multiView.Views.Add (v);
1031 multiView.ActiveViewIndex = ActiveStepIndex;
1033 RegisterApplyStyle (viewCell, StepStyle);
1034 viewCell.Controls.Add (multiView);
1035 viewRow.Cells.Add (viewCell);
1036 viewRow.Height = new Unit ("100%");
1037 contentTable.Rows.Add (viewRow);
1039 TableRow buttonRow = new TableRow ();
1040 _navigationCell = new TableCell ();
1041 _navigationCell.HorizontalAlign = HorizontalAlign.Right;
1042 RegisterApplyStyle (_navigationCell, NavigationStyle);
1043 CreateButtonBar (_navigationCell);
1044 buttonRow.Cells.Add (_navigationCell);
1045 contentTable.Rows.Add (buttonRow);
1047 Controls.SetReadonly (false);
1048 Controls.Add (wizardTable);
1049 Controls.SetReadonly (true);
1052 internal virtual void InstantiateTemplateStep(TemplatedWizardStep step)
1054 BaseWizardContainer contentTemplateContainer = new BaseWizardContainer ();
1056 if (step.ContentTemplate != null)
1057 step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1059 step.ContentTemplateContainer = contentTemplateContainer;
1060 step.Controls.Clear ();
1061 step.Controls.Add (contentTemplateContainer);
1063 BaseWizardNavigationContainer customNavigationTemplateContainer = new BaseWizardNavigationContainer ();
1065 if (step.CustomNavigationTemplate != null) {
1066 step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1067 RegisterCustomNavigation (step, customNavigationTemplateContainer);
1069 step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1072 internal void RegisterCustomNavigation (TemplatedWizardStep step, BaseWizardNavigationContainer customNavigationTemplateContainer)
1074 if (customNavigation == null)
1075 customNavigation = new Hashtable ();
1076 customNavigation [step] = customNavigationTemplateContainer;
1079 void CreateButtonBar (Control container)
1081 if(customNavigation != null && customNavigation.Values.Count > 0 ) {
1083 foreach (Control customNavigationTemplateContainer in customNavigation.Values) {
1084 customNavigationTemplateContainer.ID = "CustomNavigationTemplateContainerID" + i++;
1085 container.Controls.Add (customNavigationTemplateContainer);
1090 // StartNavContainer
1092 _startNavContainer = new StartNavigationContainer (this);
1093 _startNavContainer.ID = "StartNavigationTemplateContainerID";
1094 if (startNavigationTemplate != null)
1095 startNavigationTemplate.InstantiateIn (_startNavContainer);
1098 AddNavButtonsTable (_startNavContainer, out row);
1099 AddButtonCell (row, CreateButtonSet (StartNextButtonIDShort, MoveNextCommandName));
1100 AddButtonCell (row, CreateButtonSet (CancelButtonIDShort, CancelCommandName, false));
1101 _startNavContainer.ConfirmDefaultTemplate ();
1103 container.Controls.Add (_startNavContainer);
1108 _stepNavContainer = new StepNavigationContainer (this);
1109 _stepNavContainer.ID = "StepNavigationTemplateContainerID";
1110 if (stepNavigationTemplate != null)
1111 stepNavigationTemplate.InstantiateIn (_stepNavContainer);
1114 AddNavButtonsTable (_stepNavContainer, out row);
1115 AddButtonCell (row, CreateButtonSet (StepPreviousButtonIDShort, MovePreviousCommandName, false));
1116 AddButtonCell (row, CreateButtonSet (StepNextButtonIDShort, MoveNextCommandName));
1117 AddButtonCell (row, CreateButtonSet (CancelButtonIDShort, CancelCommandName, false));
1118 _stepNavContainer.ConfirmDefaultTemplate ();
1120 container.Controls.Add (_stepNavContainer);
1125 _finishNavContainer = new FinishNavigationContainer (this);
1126 _finishNavContainer.ID = "FinishNavigationTemplateContainerID";
1127 if (finishNavigationTemplate != null)
1128 finishNavigationTemplate.InstantiateIn (_finishNavContainer);
1131 AddNavButtonsTable (_finishNavContainer, out row);
1132 AddButtonCell (row, CreateButtonSet (FinishPreviousButtonIDShort, MovePreviousCommandName, false));
1133 AddButtonCell (row, CreateButtonSet (FinishButtonIDShort, MoveCompleteCommandName));
1134 AddButtonCell (row, CreateButtonSet (CancelButtonIDShort, CancelCommandName, false));
1135 _finishNavContainer.ConfirmDefaultTemplate ();
1137 container.Controls.Add (_finishNavContainer);
1140 static void AddNavButtonsTable (BaseWizardNavigationContainer container, out TableRow row)
1142 Table t = new Table ();
1145 row = new TableRow ();
1147 container.Controls.Add (t);
1150 Control [] CreateButtonSet (string id, string command)
1152 return CreateButtonSet (id, command, true, null);
1155 Control [] CreateButtonSet (string id, string command, bool causesValidation)
1157 return CreateButtonSet (id, command, causesValidation, null);
1160 internal Control [] CreateButtonSet (string id, string command, bool causesValidation, string validationGroup)
1162 return new Control [] {
1163 CreateButton ( id + ButtonType.Button, command, ButtonType.Button, causesValidation, validationGroup),
1164 CreateButton ( id + ButtonType.Image, command, ButtonType.Image, causesValidation, validationGroup),
1165 CreateButton ( id + ButtonType.Link, command, ButtonType.Link, causesValidation, validationGroup)
1169 Control CreateButton (string id, string command, ButtonType type, bool causesValidation, string validationGroup)
1173 case ButtonType.Button:
1174 b = CreateStandardButton ();
1176 case ButtonType.Image:
1177 b = CreateImageButton (null);
1179 case ButtonType.Link:
1180 b = CreateLinkButton ();
1183 throw new ArgumentOutOfRangeException ("type");
1187 b.EnableTheming = false;
1188 ((IButtonControl) b).CommandName = command;
1189 ((IButtonControl) b).CausesValidation = causesValidation;
1190 if(!String.IsNullOrEmpty(validationGroup))
1191 ((IButtonControl) b).ValidationGroup = validationGroup;
1193 RegisterApplyStyle (b, NavigationButtonStyle);
1198 WebControl CreateStandardButton () {
1199 Button btn = new Button ();
1203 WebControl CreateImageButton (string imageUrl) {
1204 ImageButton img = new ImageButton ();
1205 img.ImageUrl = imageUrl;
1209 WebControl CreateLinkButton () {
1210 LinkButton link = new LinkButton ();
1214 void AddButtonCell (TableRow row, params Control[] controls)
1216 TableCell cell = new TableCell ();
1217 cell.HorizontalAlign = HorizontalAlign.Right;
1218 for (int i = 0; i < controls.Length; i++)
1219 cell.Controls.Add (controls [i]);
1220 row.Cells.Add (cell);
1223 void CreateSideBar (Control container)
1225 WebControl wctl = container as WebControl;
1227 RegisterApplyStyle (wctl, SideBarStyle);
1229 if (sideBarTemplate != null) {
1230 sideBarTemplate.InstantiateIn (container);
1231 stepDatalist = container.FindControl (DataListID) as DataList;
1232 if (stepDatalist == null)
1233 throw new InvalidOperationException ("The side bar template must contain a DataList control with id '" + DataListID + "'.");
1234 stepDatalist.ItemDataBound += new DataListItemEventHandler(StepDatalistItemDataBound);
1236 stepDatalist = new DataList ();
1237 stepDatalist.ID = DataListID;
1238 stepDatalist.SelectedItemStyle.Font.Bold = true;
1239 stepDatalist.ItemTemplate = SideBarItemTemplate;
1240 container.Controls.Add (stepDatalist);
1243 stepDatalist.ItemCommand += new DataListCommandEventHandler (StepDatalistItemCommand);
1244 stepDatalist.CellSpacing = 0;
1245 stepDatalist.DataSource = WizardSteps;
1246 stepDatalist.SelectedIndex = ActiveStepIndex;
1247 stepDatalist.DataBind ();
1250 void StepDatalistItemCommand (object sender, DataListCommandEventArgs e)
1252 WizardNavigationEventArgs arg = new WizardNavigationEventArgs (ActiveStepIndex, Convert.ToInt32 (e.CommandArgument));
1253 OnSideBarButtonClick (arg);
1256 ActiveStepIndex = arg.NextStepIndex;
1259 void StepDatalistItemDataBound (object sender, DataListItemEventArgs e)
1261 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem) {
1262 IButtonControl button = (IButtonControl) e.Item.FindControl (SideBarButtonID);
1264 throw new InvalidOperationException ("SideBarList control must contain an IButtonControl with ID " + SideBarButtonID + " in every item template, this maybe include ItemTemplate, EditItemTemplate, SelectedItemTemplate or AlternatingItemTemplate if they exist.");
1266 WizardStepBase step = (WizardStepBase) e.Item.DataItem;
1268 if (button is Button)
1269 ((Button) button).UseSubmitBehavior = false;
1271 button.CommandName = Wizard.MoveToCommandName;
1272 button.CommandArgument = WizardSteps.IndexOf (step).ToString ();
1273 button.Text = step.Name;
1274 if (step.StepType == WizardStepType.Complete && button is WebControl)
1275 ((WebControl) button).Enabled = false;
1279 void AddHeaderRow (Table table)
1281 TableRow row = new TableRow ();
1282 _headerCell = new WizardHeaderCell ();
1283 _headerCell.ID = "HeaderContainer";
1284 RegisterApplyStyle (_headerCell, HeaderStyle);
1285 if (headerTemplate != null) {
1286 headerTemplate.InstantiateIn (_headerCell);
1287 _headerCell.ConfirmInitState ();
1289 row.Cells.Add (_headerCell);
1290 table.Rows.Add (row);
1293 internal void RegisterApplyStyle (WebControl control, Style style)
1295 styles.Add (new object [] { control, style });
1298 protected override Style CreateControlStyle ()
1300 TableStyle style = new TableStyle ();
1301 style.CellPadding = 0;
1302 style.CellSpacing = 0;
1306 protected override IDictionary GetDesignModeState ()
1308 throw new NotImplementedException ();
1311 protected internal override void LoadControlState (object ob)
1313 if (ob == null) return;
1314 object[] state = (object[]) ob;
1315 base.LoadControlState (state[0]);
1316 activeStepIndex = (int) state[1];
1317 history = (ArrayList) state[2];
1320 protected internal override object SaveControlState ()
1322 if (GetHistory ().Count == 0 || (int) history [0] != ActiveStepIndex)
1323 history.Insert (0, ActiveStepIndex);
1325 object bstate = base.SaveControlState ();
1326 return new object[] {
1327 bstate, activeStepIndex, history
1331 protected override void LoadViewState (object savedState)
1333 if (savedState == null) {
1334 base.LoadViewState (null);
1338 object[] states = (object[]) savedState;
1339 base.LoadViewState (states [0]);
1341 if (states[1] != null) ((IStateManager)StepStyle).LoadViewState (states[1]);
1342 if (states[2] != null) ((IStateManager)SideBarStyle).LoadViewState (states[2]);
1343 if (states[3] != null) ((IStateManager)HeaderStyle).LoadViewState (states[3]);
1344 if (states[4] != null) ((IStateManager)NavigationStyle).LoadViewState (states[4]);
1345 if (states[5] != null) ((IStateManager)SideBarButtonStyle).LoadViewState (states[5]);
1346 if (states[6] != null) ((IStateManager)CancelButtonStyle).LoadViewState (states[6]);
1347 if (states[7] != null) ((IStateManager)FinishCompleteButtonStyle).LoadViewState (states[7]);
1348 if (states[8] != null) ((IStateManager)FinishPreviousButtonStyle).LoadViewState (states[8]);
1349 if (states[9] != null) ((IStateManager)StartNextButtonStyle).LoadViewState (states[9]);
1350 if (states[10] != null) ((IStateManager)StepNextButtonStyle).LoadViewState (states[10]);
1351 if (states[11] != null) ((IStateManager)StepPreviousButtonStyle).LoadViewState (states[11]);
1352 if (states[12] != null) ((IStateManager)NavigationButtonStyle).LoadViewState (states[12]);
1353 if (states [13] != null)
1354 ControlStyle.LoadViewState (states [13]);
1357 protected override object SaveViewState ()
1359 object [] state = new object [14];
1360 state [0] = base.SaveViewState ();
1362 if (stepStyle != null) state [1] = ((IStateManager)stepStyle).SaveViewState ();
1363 if (sideBarStyle != null) state [2] = ((IStateManager)sideBarStyle).SaveViewState ();
1364 if (headerStyle != null) state [3] = ((IStateManager)headerStyle).SaveViewState ();
1365 if (navigationStyle != null) state [4] = ((IStateManager)navigationStyle).SaveViewState ();
1366 if (sideBarButtonStyle != null) state [5] = ((IStateManager)sideBarButtonStyle).SaveViewState ();
1367 if (cancelButtonStyle != null) state [6] = ((IStateManager)cancelButtonStyle).SaveViewState ();
1368 if (finishCompleteButtonStyle != null) state [7] = ((IStateManager)finishCompleteButtonStyle).SaveViewState ();
1369 if (finishPreviousButtonStyle != null) state [8] = ((IStateManager)finishPreviousButtonStyle).SaveViewState ();
1370 if (startNextButtonStyle != null) state [9] = ((IStateManager)startNextButtonStyle).SaveViewState ();
1371 if (stepNextButtonStyle != null) state [10] = ((IStateManager)stepNextButtonStyle).SaveViewState ();
1372 if (stepPreviousButtonStyle != null) state [11] = ((IStateManager)stepPreviousButtonStyle).SaveViewState ();
1373 if (navigationButtonStyle != null) state [12] = ((IStateManager)navigationButtonStyle).SaveViewState ();
1374 if (ControlStyleCreated)
1375 state [13] = ControlStyle.SaveViewState ();
1377 for (int n=0; n<state.Length; n++)
1378 if (state [n] != null) return state;
1382 protected override void TrackViewState ()
1384 base.TrackViewState();
1385 if (stepStyle != null) ((IStateManager)stepStyle).TrackViewState();
1386 if (sideBarStyle != null) ((IStateManager)sideBarStyle).TrackViewState();
1387 if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
1388 if (navigationStyle != null) ((IStateManager)navigationStyle).TrackViewState();
1389 if (sideBarButtonStyle != null) ((IStateManager)sideBarButtonStyle).TrackViewState();
1390 if (cancelButtonStyle != null) ((IStateManager)cancelButtonStyle).TrackViewState();
1391 if (finishCompleteButtonStyle != null) ((IStateManager)finishCompleteButtonStyle).TrackViewState();
1392 if (finishPreviousButtonStyle != null) ((IStateManager)finishPreviousButtonStyle).TrackViewState();
1393 if (startNextButtonStyle != null) ((IStateManager)startNextButtonStyle).TrackViewState();
1394 if (stepNextButtonStyle != null) ((IStateManager)stepNextButtonStyle).TrackViewState();
1395 if (stepPreviousButtonStyle != null) ((IStateManager)stepPreviousButtonStyle).TrackViewState();
1396 if (navigationButtonStyle != null) ((IStateManager)navigationButtonStyle).TrackViewState();
1397 if (ControlStyleCreated)
1398 ControlStyle.TrackViewState ();
1401 protected internal void RegisterCommandEvents (IButtonControl button)
1403 button.Command += ProcessCommand;
1406 void ProcessCommand (object sender, CommandEventArgs args)
1408 Control c = sender as Control;
1411 case "CancelButton":
1412 ProcessEvent ("Cancel", null);
1414 case "FinishButton":
1415 ProcessEvent ("MoveComplete", null);
1417 case "StepPreviousButton":
1418 case "FinishPreviousButton":
1419 ProcessEvent ("MovePrevious", null);
1421 case "StartNextButton":
1422 case "StepNextButton":
1423 ProcessEvent ("MoveNext", null);
1427 ProcessEvent (args.CommandName, args.CommandArgument as string);
1430 protected override bool OnBubbleEvent (object source, EventArgs e)
1432 CommandEventArgs args = e as CommandEventArgs;
1434 ProcessEvent (args.CommandName, args.CommandArgument as string);
1437 return base.OnBubbleEvent (source, e);
1440 void ProcessEvent (string commandName, string commandArg)
1442 switch (commandName) {
1444 if (CancelDestinationPageUrl.Length > 0)
1445 Context.Response.Redirect (CancelDestinationPageUrl);
1447 OnCancelButtonClick (EventArgs.Empty);
1450 case "MoveComplete":
1452 for (int n=0; n<WizardSteps.Count; n++) {
1453 if (WizardSteps [n].StepType == WizardStepType.Complete) {
1459 if (next == -1 && ActiveStepIndex == WizardSteps.Count - 1)
1460 next = ActiveStepIndex;
1462 WizardNavigationEventArgs navArgs = new WizardNavigationEventArgs (ActiveStepIndex, next);
1463 OnFinishButtonClick (navArgs);
1465 if (FinishDestinationPageUrl.Length > 0) {
1466 Context.Response.Redirect (FinishDestinationPageUrl);
1470 if (next != -1 && !navArgs.Cancel)
1471 ActiveStepIndex = next;
1476 if (ActiveStepIndex < WizardSteps.Count - 1) {
1477 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex + 1);
1478 int curStep = ActiveStepIndex;
1479 OnNextButtonClick (args);
1480 if (!args.Cancel && curStep == activeStepIndex)
1485 case "MovePrevious":
1486 if (ActiveStepIndex > 0) {
1487 WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex - 1);
1488 int curStep = ActiveStepIndex;
1489 OnPreviousButtonClick (args);
1491 if (curStep == activeStepIndex)
1493 if (history != null && activeStepIndex < curStep)
1494 history.Remove (curStep);
1500 int newb = int.Parse (commandArg);
1501 ActiveStepIndex = newb;
1506 internal void UpdateViews ()
1508 ChildControlsCreated = false;
1511 protected internal override void Render (HtmlTextWriter writer)
1513 PrepareControlHierarchy ();
1515 if (LayoutTemplate == null)
1517 wizardTable.Render (writer);
1520 RenderChildren (writer);
1524 void PrepareControlHierarchy ()
1527 if (LayoutTemplate == null) {
1530 if (!_headerCell.Initialized) {
1531 if (String.IsNullOrEmpty (HeaderText))
1532 _headerCell.Parent.Visible = false;
1534 _headerCell.Text = HeaderText;
1537 if (ActiveStep.StepType == WizardStepType.Complete)
1538 _headerCell.Parent.Visible = false;
1541 WizardStepCollection steps = WizardSteps;
1543 if (steps == null || steps.Count == 0)
1549 if (stepDatalist != null) {
1550 stepDatalist.SelectedIndex = ActiveStepIndex;
1551 stepDatalist.DataBind ();
1553 if (ActiveStep.StepType == WizardStepType.Complete)
1554 stepDatalist.NamingContainer.Visible = false;
1558 TemplatedWizardStep templateStep = ActiveStep as TemplatedWizardStep;
1559 if (templateStep != null) {
1560 BaseWizardContainer contentContainer = templateStep.ContentTemplateContainer as BaseWizardContainer;
1561 if (contentContainer != null)
1562 contentContainer.PrepareControlHierarchy ();
1566 if (customNavigation != null) {
1567 foreach (Control c in customNavigation.Values)
1570 _startNavContainer.Visible = false;
1571 _stepNavContainer.Visible = false;
1572 _finishNavContainer.Visible = false;
1574 BaseWizardNavigationContainer currentNavContainer = GetCurrentNavContainer ();
1575 if (currentNavContainer == null) {
1576 if (_navigationCell != null)
1577 _navigationCell.Parent.Visible = false;
1579 currentNavContainer.Visible = true;
1580 currentNavContainer.PrepareControlHierarchy ();
1581 if (_navigationCell != null && !currentNavContainer.Visible)
1582 _navigationCell.Parent.Visible = false;
1585 foreach (object [] styleDef in styles)
1586 ((WebControl) styleDef [0]).ApplyStyle ((Style) styleDef [1]);
1589 BaseWizardNavigationContainer GetCurrentNavContainer ()
1591 if (customNavigation != null && customNavigation [ActiveStep] != null) {
1592 return (BaseWizardNavigationContainer) customNavigation [ActiveStep];
1595 WizardStepType stepType = GetStepType (ActiveStep, ActiveStepIndex);
1597 case WizardStepType.Start:
1598 return _startNavContainer;
1599 case WizardStepType.Step:
1600 return _stepNavContainer;
1601 case WizardStepType.Finish:
1602 return _finishNavContainer;
1609 sealed class TableCellNamingContainer : TableCell, INamingContainer, INonBindingContainer
1611 string skipLinkText;
1615 protected internal override void RenderChildren (HtmlTextWriter writer)
1618 // <a href="#ID_SkipLink">
1619 writer.AddAttribute (HtmlTextWriterAttribute.Href, "#" + clientId + "_SkipLink");
1620 writer.RenderBeginTag (HtmlTextWriterTag.A);
1622 // <img alt="" height="0" width="0" src="" style="border-width:0px;"/>
1623 writer.AddAttribute (HtmlTextWriterAttribute.Alt, skipLinkText);
1624 writer.AddAttribute (HtmlTextWriterAttribute.Height, "0");
1625 writer.AddAttribute (HtmlTextWriterAttribute.Width, "0");
1628 ClientScriptManager csm;
1631 csm = page.ClientScript;
1633 csm = new ClientScriptManager (null);
1634 writer.AddAttribute (HtmlTextWriterAttribute.Src, csm.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif"));
1635 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, "0px");
1636 writer.RenderBeginTag (HtmlTextWriterTag.Img);
1637 writer.RenderEndTag ();
1639 writer.RenderEndTag (); // </a>
1642 base.RenderChildren (writer);
1645 writer.AddAttribute (HtmlTextWriterAttribute.Id, "SkipLink");
1646 writer.RenderBeginTag (HtmlTextWriterTag.A);
1647 writer.RenderEndTag ();
1651 public TableCellNamingContainer (string skipLinkText, string clientId)
1653 this.skipLinkText = skipLinkText;
1654 this.clientId = clientId;
1655 this.haveSkipLink = !String.IsNullOrEmpty (skipLinkText);
1659 sealed class SideBarButtonTemplate: ITemplate
1663 public SideBarButtonTemplate (Wizard wizard)
1665 this.wizard = wizard;
1668 public void InstantiateIn (Control control)
1670 LinkButton b = new LinkButton ();
1671 wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1672 control.Controls.Add (b);
1673 control.DataBinding += Bound;
1676 void Bound (object s, EventArgs args)
1678 WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1680 DataListItem c = (DataListItem) s;
1681 LinkButton b = (LinkButton) c.Controls[0];
1682 b.ID = SideBarButtonID;
1683 b.CommandName = Wizard.MoveToCommandName;
1684 b.CommandArgument = wizard.WizardSteps.IndexOf (step).ToString ();
1686 if (step.StepType == WizardStepType.Complete)
1692 class WizardHeaderCell : TableCell, INamingContainer, INonBindingContainer
1696 public bool Initialized {
1697 get { return _initialized; }
1700 public WizardHeaderCell ()
1704 public void ConfirmInitState ()
1706 _initialized = true;
1710 internal abstract class DefaultNavigationContainer : BaseWizardNavigationContainer
1715 protected Wizard Wizard {
1716 get { return _wizard; }
1719 protected DefaultNavigationContainer (Wizard wizard)
1724 public override sealed void PrepareControlHierarchy ()
1730 protected abstract void UpdateState ();
1732 public void ConfirmDefaultTemplate ()
1737 protected void UpdateNavButtonState (string id, string text, string image, Style style)
1739 WebControl b = (WebControl) FindControl (id);
1740 foreach (Control c in b.Parent.Controls)
1743 ((IButtonControl) b).Text = text;
1744 ImageButton imgbtn = b as ImageButton;
1746 imgbtn.ImageUrl = image;
1748 b.ApplyStyle (style);
1752 sealed class StartNavigationContainer : DefaultNavigationContainer
1754 public StartNavigationContainer (Wizard wizard)
1759 protected override void UpdateState ()
1761 bool visible = false;
1764 if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex + 1)) {
1766 UpdateNavButtonState (Wizard.StartNextButtonIDShort + Wizard.StartNextButtonType, Wizard.StartNextButtonText, Wizard.StartNextButtonImageUrl, Wizard.StartNextButtonStyle);
1768 ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1771 if (Wizard.DisplayCancelButton) {
1773 UpdateNavButtonState (Wizard.CancelButtonIDShort + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1775 ((Table) Controls [0]).Rows [0].Cells [1].Visible = false;
1781 sealed class StepNavigationContainer : DefaultNavigationContainer
1783 public StepNavigationContainer (Wizard wizard)
1788 protected override void UpdateState ()
1790 bool visible = false;
1792 if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex - 1)) {
1794 UpdateNavButtonState (Wizard.StepPreviousButtonIDShort + Wizard.StepPreviousButtonType, Wizard.StepPreviousButtonText, Wizard.StepPreviousButtonImageUrl, Wizard.StepPreviousButtonStyle);
1796 ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1799 if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex + 1)) {
1801 UpdateNavButtonState (Wizard.StepNextButtonIDShort + Wizard.StepNextButtonType, Wizard.StepNextButtonText, Wizard.StepNextButtonImageUrl, Wizard.StepNextButtonStyle);
1803 ((Table) Controls [0]).Rows [0].Cells [1].Visible = false;
1806 if (Wizard.DisplayCancelButton) {
1808 UpdateNavButtonState (Wizard.CancelButtonIDShort + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1810 ((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
1816 sealed class FinishNavigationContainer : DefaultNavigationContainer
1818 public FinishNavigationContainer (Wizard wizard)
1823 protected override void UpdateState ()
1826 int previous = Wizard.ActiveStepIndex - 1;
1827 if (previous >= 0 && Wizard.AllowNavigationToStep (previous)) {
1828 UpdateNavButtonState (Wizard.FinishPreviousButtonIDShort + Wizard.FinishPreviousButtonType, Wizard.FinishPreviousButtonText, Wizard.FinishPreviousButtonImageUrl, Wizard.FinishPreviousButtonStyle);
1830 ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1833 UpdateNavButtonState (Wizard.FinishButtonIDShort + Wizard.FinishCompleteButtonType, Wizard.FinishCompleteButtonText, Wizard.FinishCompleteButtonImageUrl, Wizard.FinishCompleteButtonStyle);
1836 if (Wizard.DisplayCancelButton) {
1837 UpdateNavButtonState (Wizard.CancelButtonIDShort + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1839 ((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
1843 internal class BaseWizardContainer : Table, INamingContainer, INonBindingContainer
1845 public TableCell InnerCell {
1846 get { return Rows [0].Cells [0]; }
1849 internal BaseWizardContainer ()
1855 TableRow row = new TableRow ();
1856 TableCell cell = new TableCell ();
1858 cell.ControlStyle.Width = Unit.Percentage (100);
1859 cell.ControlStyle.Height = Unit.Percentage (100);
1861 row.Cells.Add (cell);
1863 this.ControlStyle.Width = Unit.Percentage (100);
1864 this.ControlStyle.Height = Unit.Percentage (100);
1865 this.CellPadding = 0;
1866 this.CellSpacing = 0;
1868 this.Rows.Add (row);
1871 public virtual void PrepareControlHierarchy ()
1876 internal class BaseWizardNavigationContainer : Control, INamingContainer, INonBindingContainer
1878 internal BaseWizardNavigationContainer ()
1882 public virtual void PrepareControlHierarchy ()
1887 internal abstract class DefaultContentContainer : BaseWizardContainer
1892 protected bool IsDefaultTemplate {
1893 get { return _isDefault; }
1896 protected Wizard Wizard {
1897 get { return _wizard; }
1900 protected DefaultContentContainer (Wizard wizard)
1905 public override sealed void PrepareControlHierarchy ()
1911 protected abstract void UpdateState ();
1913 public void ConfirmDefaultTemplate ()