2
0

Wizard.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. //
  2. // System.Web.UI.WebControls.Wizard
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc. (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.Collections;
  32. using System.ComponentModel;
  33. namespace System.Web.UI.WebControls
  34. {
  35. [DefaultEventAttribute ("FinishButtonClick")]
  36. [BindableAttribute (false)]
  37. [DesignerAttribute ("System.Web.UI.Design.WebControls.WizardDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  38. [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>")]
  39. public class Wizard: CompositeControl
  40. {
  41. public static readonly string CancelCommandName = "Cancel";
  42. public static readonly string MoveCompleteCommandName = "MoveComplete";
  43. public static readonly string MoveNextCommandName = "MoveNext";
  44. public static readonly string MovePreviousCommandName = "MovePrevious";
  45. public static readonly string MoveToCommandName = "Move";
  46. protected static readonly string CancelButtonID = "CancelButton";
  47. protected static readonly string CustomFinishButtonID = "CustomFinishButton";
  48. protected static readonly string CustomNextButtonID = "CustomNextButton";
  49. protected static readonly string CustomPreviousButtonID = "CustomPreviousButton";
  50. protected static readonly string DataListID = "SideBarList";
  51. protected static readonly string FinishButtonID = "FinishButton";
  52. protected static readonly string FinishPreviousButtonID = "FinishPreviousButton";
  53. protected static readonly string SideBarButtonID = "SideBarButton";
  54. protected static readonly string StartNextButtonID = "StartNextButton";
  55. protected static readonly string StepNextButtonID = "StepNextButton";
  56. protected static readonly string StepPreviousButtonID = "StepPreviousButton";
  57. WizardStepCollection steps;
  58. // View state
  59. TableItemStyle stepStyle;
  60. TableItemStyle sideBarStyle;
  61. TableItemStyle headerStyle;
  62. TableItemStyle navigationStyle;
  63. Style sideBarButtonStyle;
  64. Style cancelButtonStyle;
  65. Style finishCompleteButtonStyle;
  66. Style finishPreviousButtonStyle;
  67. Style startNextButtonStyle;
  68. Style stepNextButtonStyle;
  69. Style stepPreviousButtonStyle;
  70. Style navigationButtonStyle;
  71. ITemplate finishNavigationTemplate;
  72. ITemplate startNavigationTemplate;
  73. ITemplate stepNavigationTemplate;
  74. ITemplate headerTemplate;
  75. ITemplate sideBarTemplate;
  76. // Control state
  77. int activeStepIndex = -1;
  78. bool inited = false;
  79. ArrayList history;
  80. Table wizardTable;
  81. WizardHeaderCell _headerCell;
  82. TableCell _navigationCell;
  83. StartNavigationContainer _startNavContainer;
  84. StepNavigationContainer _stepNavContainer;
  85. FinishNavigationContainer _finishNavContainer;
  86. MultiView multiView;
  87. DataList stepDatalist;
  88. ArrayList styles = new ArrayList ();
  89. Hashtable customNavigation;
  90. private static readonly object ActiveStepChangedEvent = new object();
  91. private static readonly object CancelButtonClickEvent = new object();
  92. private static readonly object FinishButtonClickEvent = new object();
  93. private static readonly object NextButtonClickEvent = new object();
  94. private static readonly object PreviousButtonClickEvent = new object();
  95. private static readonly object SideBarButtonClickEvent = new object();
  96. public event EventHandler ActiveStepChanged {
  97. add { Events.AddHandler (ActiveStepChangedEvent, value); }
  98. remove { Events.RemoveHandler (ActiveStepChangedEvent, value); }
  99. }
  100. public event EventHandler CancelButtonClick {
  101. add { Events.AddHandler (CancelButtonClickEvent, value); }
  102. remove { Events.RemoveHandler (CancelButtonClickEvent, value); }
  103. }
  104. public event WizardNavigationEventHandler FinishButtonClick {
  105. add { Events.AddHandler (FinishButtonClickEvent, value); }
  106. remove { Events.RemoveHandler (FinishButtonClickEvent, value); }
  107. }
  108. public event WizardNavigationEventHandler NextButtonClick {
  109. add { Events.AddHandler (NextButtonClickEvent, value); }
  110. remove { Events.RemoveHandler (NextButtonClickEvent, value); }
  111. }
  112. public event WizardNavigationEventHandler PreviousButtonClick {
  113. add { Events.AddHandler (PreviousButtonClickEvent, value); }
  114. remove { Events.RemoveHandler (PreviousButtonClickEvent, value); }
  115. }
  116. public event WizardNavigationEventHandler SideBarButtonClick {
  117. add { Events.AddHandler (SideBarButtonClickEvent, value); }
  118. remove { Events.RemoveHandler (SideBarButtonClickEvent, value); }
  119. }
  120. protected virtual void OnActiveStepChanged (object source, EventArgs e)
  121. {
  122. if (Events != null) {
  123. EventHandler eh = (EventHandler) Events [ActiveStepChangedEvent];
  124. if (eh != null) eh (source, e);
  125. }
  126. }
  127. protected virtual void OnCancelButtonClick (EventArgs e)
  128. {
  129. if (Events != null) {
  130. EventHandler eh = (EventHandler) Events [CancelButtonClickEvent];
  131. if (eh != null) eh (this, e);
  132. }
  133. }
  134. protected virtual void OnFinishButtonClick (WizardNavigationEventArgs e)
  135. {
  136. if (Events != null) {
  137. WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [FinishButtonClickEvent];
  138. if (eh != null) eh (this, e);
  139. }
  140. }
  141. protected virtual void OnNextButtonClick (WizardNavigationEventArgs e)
  142. {
  143. if (Events != null) {
  144. WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [NextButtonClickEvent];
  145. if (eh != null) eh (this, e);
  146. }
  147. }
  148. protected virtual void OnPreviousButtonClick (WizardNavigationEventArgs e)
  149. {
  150. if (Events != null) {
  151. WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [PreviousButtonClickEvent];
  152. if (eh != null) eh (this, e);
  153. }
  154. }
  155. protected virtual void OnSideBarButtonClick (WizardNavigationEventArgs e)
  156. {
  157. if (Events != null) {
  158. WizardNavigationEventHandler eh = (WizardNavigationEventHandler) Events [SideBarButtonClickEvent];
  159. if (eh != null) eh (this, e);
  160. }
  161. }
  162. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  163. [BrowsableAttribute (false)]
  164. public WizardStepBase ActiveStep {
  165. get {
  166. if (ActiveStepIndex < -1 || ActiveStepIndex >= WizardSteps.Count)
  167. throw new InvalidOperationException ("ActiveStepIndex has an invalid value.");
  168. if (ActiveStepIndex == -1) return null;
  169. return WizardSteps [activeStepIndex];
  170. }
  171. }
  172. [DefaultValueAttribute (-1)]
  173. [ThemeableAttribute (false)]
  174. public virtual int ActiveStepIndex {
  175. get {
  176. return activeStepIndex;
  177. }
  178. set {
  179. if (value < -1 || (value > WizardSteps.Count && (inited || WizardSteps.Count > 0)))
  180. throw new ArgumentOutOfRangeException ("The ActiveStepIndex must be less than WizardSteps.Count and at least -1");
  181. if (inited && !AllowNavigationToStep (value))
  182. return;
  183. activeStepIndex = value;
  184. if (inited) {
  185. multiView.ActiveViewIndex = value;
  186. if (stepDatalist != null) {
  187. stepDatalist.SelectedIndex = value;
  188. stepDatalist.DataBind ();
  189. }
  190. OnActiveStepChanged (this, EventArgs.Empty);
  191. }
  192. }
  193. }
  194. [UrlPropertyAttribute]
  195. [DefaultValueAttribute ("")]
  196. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  197. public virtual string CancelButtonImageUrl {
  198. get {
  199. object v = ViewState ["CancelButtonImageUrl"];
  200. return v != null ? (string)v : string.Empty;
  201. }
  202. set {
  203. ViewState ["CancelButtonImageUrl"] = value;
  204. }
  205. }
  206. [DefaultValueAttribute (null)]
  207. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  208. [NotifyParentPropertyAttribute (true)]
  209. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  210. public Style CancelButtonStyle {
  211. get {
  212. if (cancelButtonStyle == null) {
  213. cancelButtonStyle = new Style ();
  214. if (IsTrackingViewState)
  215. ((IStateManager)cancelButtonStyle).TrackViewState ();
  216. }
  217. return cancelButtonStyle;
  218. }
  219. }
  220. [LocalizableAttribute (true)]
  221. public virtual string CancelButtonText {
  222. get {
  223. object v = ViewState ["CancelButtonText"];
  224. return v != null ? (string)v : "Cancel";
  225. }
  226. set {
  227. ViewState ["CancelButtonText"] = value;
  228. }
  229. }
  230. [DefaultValueAttribute (ButtonType.Button)]
  231. public virtual ButtonType CancelButtonType {
  232. get {
  233. object v = ViewState ["CancelButtonType"];
  234. return v != null ? (ButtonType)v : ButtonType.Button;
  235. }
  236. set {
  237. ViewState ["CancelButtonType"] = value;
  238. }
  239. }
  240. [UrlPropertyAttribute]
  241. [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  242. [DefaultValueAttribute ("")]
  243. public virtual string CancelDestinationPageUrl {
  244. get {
  245. object v = ViewState ["CancelDestinationPageUrl"];
  246. return v != null ? (string)v : string.Empty;
  247. }
  248. set {
  249. ViewState ["CancelDestinationPageUrl"] = value;
  250. }
  251. }
  252. [DefaultValueAttribute (0)]
  253. public virtual int CellPadding {
  254. get {
  255. if (ControlStyleCreated)
  256. return ((TableStyle) ControlStyle).CellPadding;
  257. return 0;
  258. }
  259. set {
  260. ((TableStyle) ControlStyle).CellPadding = value;
  261. }
  262. }
  263. [DefaultValueAttribute (0)]
  264. public virtual int CellSpacing {
  265. get {
  266. if (ControlStyleCreated)
  267. return ((TableStyle) ControlStyle).CellSpacing;
  268. return 0;
  269. }
  270. set {
  271. ((TableStyle) ControlStyle).CellSpacing = value;
  272. }
  273. }
  274. [DefaultValueAttribute (false)]
  275. [ThemeableAttribute (false)]
  276. public virtual bool DisplayCancelButton {
  277. get {
  278. object v = ViewState ["DisplayCancelButton"];
  279. return v != null ? (bool) v : false;
  280. }
  281. set {
  282. ViewState ["DisplayCancelButton"] = value;
  283. }
  284. }
  285. [DefaultValueAttribute (true)]
  286. [ThemeableAttribute (false)]
  287. public virtual bool DisplaySideBar {
  288. get {
  289. object v = ViewState ["DisplaySideBar"];
  290. return v != null ? (bool) v : true;
  291. }
  292. set {
  293. ViewState ["DisplaySideBar"] = value;
  294. UpdateViews ();
  295. }
  296. }
  297. [UrlPropertyAttribute]
  298. [DefaultValueAttribute ("")]
  299. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  300. public virtual string FinishCompleteButtonImageUrl {
  301. get {
  302. object v = ViewState ["FinishCompleteButtonImageUrl"];
  303. return v != null ? (string)v : string.Empty;
  304. }
  305. set {
  306. ViewState ["FinishCompleteButtonImageUrl"] = value;
  307. }
  308. }
  309. [DefaultValueAttribute (null)]
  310. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  311. [NotifyParentPropertyAttribute (true)]
  312. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  313. public Style FinishCompleteButtonStyle {
  314. get {
  315. if (finishCompleteButtonStyle == null) {
  316. finishCompleteButtonStyle = new Style ();
  317. if (IsTrackingViewState)
  318. ((IStateManager)finishCompleteButtonStyle).TrackViewState ();
  319. }
  320. return finishCompleteButtonStyle;
  321. }
  322. }
  323. [LocalizableAttribute (true)]
  324. public virtual string FinishCompleteButtonText {
  325. get {
  326. object v = ViewState ["FinishCompleteButtonText"];
  327. return v != null ? (string)v : "Finish";
  328. }
  329. set {
  330. ViewState ["FinishCompleteButtonText"] = value;
  331. }
  332. }
  333. [DefaultValueAttribute (ButtonType.Button)]
  334. public virtual ButtonType FinishCompleteButtonType {
  335. get {
  336. object v = ViewState ["FinishCompleteButtonType"];
  337. return v != null ? (ButtonType)v : ButtonType.Button;
  338. }
  339. set {
  340. ViewState ["FinishCompleteButtonType"] = value;
  341. }
  342. }
  343. [UrlPropertyAttribute]
  344. [EditorAttribute ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  345. [DefaultValueAttribute ("")]
  346. public virtual string FinishDestinationPageUrl {
  347. get {
  348. object v = ViewState ["FinishDestinationPageUrl"];
  349. return v != null ? (string)v : string.Empty;
  350. }
  351. set {
  352. ViewState ["FinishDestinationPageUrl"] = value;
  353. }
  354. }
  355. [DefaultValue (null)]
  356. [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
  357. [PersistenceMode (PersistenceMode.InnerProperty)]
  358. [Browsable (false)]
  359. public virtual ITemplate FinishNavigationTemplate {
  360. get { return finishNavigationTemplate; }
  361. set { finishNavigationTemplate = value; UpdateViews (); }
  362. }
  363. [UrlPropertyAttribute]
  364. [DefaultValueAttribute ("")]
  365. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  366. public virtual string FinishPreviousButtonImageUrl {
  367. get {
  368. object v = ViewState ["FinishPreviousButtonImageUrl"];
  369. return v != null ? (string)v : string.Empty;
  370. }
  371. set {
  372. ViewState ["FinishPreviousButtonImageUrl"] = value;
  373. }
  374. }
  375. [DefaultValueAttribute (null)]
  376. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  377. [NotifyParentPropertyAttribute (true)]
  378. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  379. public Style FinishPreviousButtonStyle {
  380. get {
  381. if (finishPreviousButtonStyle == null) {
  382. finishPreviousButtonStyle = new Style ();
  383. if (IsTrackingViewState)
  384. ((IStateManager)finishPreviousButtonStyle).TrackViewState ();
  385. }
  386. return finishPreviousButtonStyle;
  387. }
  388. }
  389. [LocalizableAttribute (true)]
  390. public virtual string FinishPreviousButtonText {
  391. get {
  392. object v = ViewState ["FinishPreviousButtonText"];
  393. return v != null ? (string)v : "Previous";
  394. }
  395. set {
  396. ViewState ["FinishPreviousButtonText"] = value;
  397. }
  398. }
  399. [DefaultValueAttribute (ButtonType.Button)]
  400. public virtual ButtonType FinishPreviousButtonType {
  401. get {
  402. object v = ViewState ["FinishPreviousButtonType"];
  403. return v != null ? (ButtonType)v : ButtonType.Button;
  404. }
  405. set {
  406. ViewState ["FinishPreviousButtonType"] = value;
  407. }
  408. }
  409. [DefaultValueAttribute (null)]
  410. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  411. [NotifyParentPropertyAttribute (true)]
  412. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  413. public TableItemStyle HeaderStyle {
  414. get {
  415. if (headerStyle == null) {
  416. headerStyle = new TableItemStyle ();
  417. if (IsTrackingViewState)
  418. ((IStateManager)headerStyle).TrackViewState ();
  419. }
  420. return headerStyle;
  421. }
  422. }
  423. [DefaultValue (null)]
  424. [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
  425. [PersistenceMode (PersistenceMode.InnerProperty)]
  426. [Browsable (false)]
  427. public virtual ITemplate HeaderTemplate {
  428. get { return headerTemplate; }
  429. set { headerTemplate = value; UpdateViews (); }
  430. }
  431. [DefaultValueAttribute ("")]
  432. [LocalizableAttribute (true)]
  433. public virtual string HeaderText {
  434. get {
  435. object v = ViewState ["HeaderText"];
  436. return v != null ? (string)v : string.Empty;
  437. }
  438. set {
  439. ViewState ["HeaderText"] = value;
  440. }
  441. }
  442. [DefaultValueAttribute (null)]
  443. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  444. [NotifyParentPropertyAttribute (true)]
  445. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  446. public Style NavigationButtonStyle {
  447. get {
  448. if (navigationButtonStyle == null) {
  449. navigationButtonStyle = new Style ();
  450. if (IsTrackingViewState)
  451. ((IStateManager)navigationButtonStyle).TrackViewState ();
  452. }
  453. return navigationButtonStyle;
  454. }
  455. }
  456. [DefaultValueAttribute (null)]
  457. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  458. [NotifyParentPropertyAttribute (true)]
  459. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  460. public TableItemStyle NavigationStyle {
  461. get {
  462. if (navigationStyle == null) {
  463. navigationStyle = new TableItemStyle ();
  464. if (IsTrackingViewState)
  465. ((IStateManager)navigationStyle).TrackViewState ();
  466. }
  467. return navigationStyle;
  468. }
  469. }
  470. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  471. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  472. [DefaultValueAttribute (null)]
  473. [NotifyParentPropertyAttribute (true)]
  474. public TableItemStyle SideBarStyle {
  475. get {
  476. if (sideBarStyle == null) {
  477. sideBarStyle = new TableItemStyle ();
  478. if (IsTrackingViewState)
  479. ((IStateManager)sideBarStyle).TrackViewState ();
  480. }
  481. return sideBarStyle;
  482. }
  483. }
  484. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  485. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  486. [DefaultValueAttribute (null)]
  487. [NotifyParentPropertyAttribute (true)]
  488. public Style SideBarButtonStyle {
  489. get {
  490. if (sideBarButtonStyle == null) {
  491. sideBarButtonStyle = new Style ();
  492. if (IsTrackingViewState)
  493. ((IStateManager)sideBarButtonStyle).TrackViewState ();
  494. }
  495. return sideBarButtonStyle;
  496. }
  497. }
  498. [DefaultValue (null)]
  499. [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
  500. [PersistenceMode (PersistenceMode.InnerProperty)]
  501. [Browsable (false)]
  502. public virtual ITemplate SideBarTemplate {
  503. get { return sideBarTemplate; }
  504. set { sideBarTemplate = value; UpdateViews (); }
  505. }
  506. [Localizable (true)]
  507. public virtual string SkipLinkText
  508. {
  509. get
  510. {
  511. object v = ViewState ["SkipLinkText"];
  512. return v != null ? (string) v : "Skip Navigation Links.";
  513. }
  514. set
  515. {
  516. ViewState ["SkipLinkText"] = value;
  517. }
  518. }
  519. [DefaultValue (null)]
  520. [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
  521. [PersistenceMode (PersistenceMode.InnerProperty)]
  522. [Browsable (false)]
  523. public virtual ITemplate StartNavigationTemplate {
  524. get { return startNavigationTemplate; }
  525. set { startNavigationTemplate = value; UpdateViews (); }
  526. }
  527. [UrlPropertyAttribute]
  528. [DefaultValueAttribute ("")]
  529. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  530. public virtual string StartNextButtonImageUrl {
  531. get {
  532. object v = ViewState ["StartNextButtonImageUrl"];
  533. return v != null ? (string)v : string.Empty;
  534. }
  535. set {
  536. ViewState ["StartNextButtonImageUrl"] = value;
  537. }
  538. }
  539. [DefaultValueAttribute (null)]
  540. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  541. [NotifyParentPropertyAttribute (true)]
  542. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  543. public Style StartNextButtonStyle {
  544. get {
  545. if (startNextButtonStyle == null) {
  546. startNextButtonStyle = new Style ();
  547. if (IsTrackingViewState)
  548. ((IStateManager)startNextButtonStyle).TrackViewState ();
  549. }
  550. return startNextButtonStyle;
  551. }
  552. }
  553. [LocalizableAttribute (true)]
  554. public virtual string StartNextButtonText {
  555. get {
  556. object v = ViewState ["StartNextButtonText"];
  557. return v != null ? (string)v : "Next";
  558. }
  559. set {
  560. ViewState ["StartNextButtonText"] = value;
  561. }
  562. }
  563. [DefaultValueAttribute (ButtonType.Button)]
  564. public virtual ButtonType StartNextButtonType {
  565. get {
  566. object v = ViewState ["StartNextButtonType"];
  567. return v != null ? (ButtonType)v : ButtonType.Button;
  568. }
  569. set {
  570. ViewState ["StartNextButtonType"] = value;
  571. }
  572. }
  573. [DefaultValue (null)]
  574. [TemplateContainer (typeof(Wizard), BindingDirection.OneWay)]
  575. [PersistenceMode (PersistenceMode.InnerProperty)]
  576. [Browsable (false)]
  577. public virtual ITemplate StepNavigationTemplate {
  578. get { return stepNavigationTemplate; }
  579. set { stepNavigationTemplate = value; UpdateViews (); }
  580. }
  581. [UrlPropertyAttribute]
  582. [DefaultValueAttribute ("")]
  583. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  584. public virtual string StepNextButtonImageUrl {
  585. get {
  586. object v = ViewState ["StepNextButtonImageUrl"];
  587. return v != null ? (string)v : string.Empty;
  588. }
  589. set {
  590. ViewState ["StepNextButtonImageUrl"] = value;
  591. }
  592. }
  593. [DefaultValueAttribute (null)]
  594. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  595. [NotifyParentPropertyAttribute (true)]
  596. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  597. public Style StepNextButtonStyle {
  598. get {
  599. if (stepNextButtonStyle == null) {
  600. stepNextButtonStyle = new Style ();
  601. if (IsTrackingViewState)
  602. ((IStateManager)stepNextButtonStyle).TrackViewState ();
  603. }
  604. return stepNextButtonStyle;
  605. }
  606. }
  607. [LocalizableAttribute (true)]
  608. public virtual string StepNextButtonText {
  609. get {
  610. object v = ViewState ["StepNextButtonText"];
  611. return v != null ? (string)v : "Next";
  612. }
  613. set {
  614. ViewState ["StepNextButtonText"] = value;
  615. }
  616. }
  617. [DefaultValueAttribute (ButtonType.Button)]
  618. public virtual ButtonType StepNextButtonType {
  619. get {
  620. object v = ViewState ["StepNextButtonType"];
  621. return v != null ? (ButtonType)v : ButtonType.Button;
  622. }
  623. set {
  624. ViewState ["StepNextButtonType"] = value;
  625. }
  626. }
  627. [UrlPropertyAttribute]
  628. [DefaultValueAttribute ("")]
  629. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  630. public virtual string StepPreviousButtonImageUrl {
  631. get {
  632. object v = ViewState ["StepPreviousButtonImageUrl"];
  633. return v != null ? (string)v : string.Empty;
  634. }
  635. set {
  636. ViewState ["StepPreviousButtonImageUrl"] = value;
  637. }
  638. }
  639. [DefaultValueAttribute (null)]
  640. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  641. [NotifyParentPropertyAttribute (true)]
  642. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  643. public Style StepPreviousButtonStyle {
  644. get {
  645. if (stepPreviousButtonStyle == null) {
  646. stepPreviousButtonStyle = new Style ();
  647. if (IsTrackingViewState)
  648. ((IStateManager)stepPreviousButtonStyle).TrackViewState ();
  649. }
  650. return stepPreviousButtonStyle;
  651. }
  652. }
  653. [LocalizableAttribute (true)]
  654. public virtual string StepPreviousButtonText {
  655. get {
  656. object v = ViewState ["StepPreviousButtonText"];
  657. return v != null ? (string)v : "Previous";
  658. }
  659. set {
  660. ViewState ["StepPreviousButtonText"] = value;
  661. }
  662. }
  663. [DefaultValueAttribute (ButtonType.Button)]
  664. public virtual ButtonType StepPreviousButtonType {
  665. get {
  666. object v = ViewState ["StepPreviousButtonType"];
  667. return v != null ? (ButtonType)v : ButtonType.Button;
  668. }
  669. set {
  670. ViewState ["StepPreviousButtonType"] = value;
  671. }
  672. }
  673. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  674. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  675. [DefaultValueAttribute (null)]
  676. [NotifyParentPropertyAttribute (true)]
  677. public TableItemStyle StepStyle {
  678. get {
  679. if (stepStyle == null) {
  680. stepStyle = new TableItemStyle ();
  681. if (IsTrackingViewState)
  682. ((IStateManager)stepStyle).TrackViewState ();
  683. }
  684. return stepStyle;
  685. }
  686. }
  687. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  688. [EditorAttribute ("System.Web.UI.Design.WebControls.WizardStepCollectionEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  689. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  690. [ThemeableAttribute (false)]
  691. public virtual WizardStepCollection WizardSteps {
  692. get {
  693. if (steps == null)
  694. steps = new WizardStepCollection (this);
  695. return steps;
  696. }
  697. }
  698. protected virtual new HtmlTextWriterTag TagKey
  699. {
  700. get {
  701. return HtmlTextWriterTag.Table;
  702. }
  703. }
  704. internal virtual ITemplate SideBarItemTemplate
  705. {
  706. get { return new SideBarButtonTemplate (this); }
  707. }
  708. public ICollection GetHistory ()
  709. {
  710. if (history == null) history = new ArrayList ();
  711. return history;
  712. }
  713. public void MoveTo (WizardStepBase wizardStep)
  714. {
  715. if (wizardStep == null) throw new ArgumentNullException ("wizardStep");
  716. int i = WizardSteps.IndexOf (wizardStep);
  717. if (i == -1) throw new ArgumentException ("The provided wizard step does not belong to this wizard.");
  718. ActiveStepIndex = i;
  719. }
  720. public WizardStepType GetStepType (WizardStepBase wizardStep, int index)
  721. {
  722. if (wizardStep.StepType == WizardStepType.Auto) {
  723. if ((index == WizardSteps.Count - 1) ||
  724. (WizardSteps.Count > 2 &&
  725. WizardSteps[WizardSteps.Count - 1].StepType == WizardStepType.Complete &&
  726. index == WizardSteps.Count - 2))
  727. return WizardStepType.Finish;
  728. else if (index == 0)
  729. return WizardStepType.Start;
  730. else
  731. return WizardStepType.Step;
  732. } else
  733. return wizardStep.StepType;
  734. }
  735. protected virtual bool AllowNavigationToStep (int index)
  736. {
  737. if (index < 0 || index >= WizardSteps.Count) return false;
  738. if (history == null) return true;
  739. if (!history.Contains (index)) return true;
  740. return WizardSteps [index].AllowReturn;
  741. }
  742. protected internal override void OnInit (EventArgs e)
  743. {
  744. Page.RegisterRequiresControlState (this);
  745. base.OnInit (e);
  746. if (ActiveStepIndex == -1)
  747. ActiveStepIndex = 0;
  748. EnsureChildControls ();
  749. inited = true;
  750. }
  751. protected override ControlCollection CreateControlCollection ()
  752. {
  753. ControlCollection col = new ControlCollection (this);
  754. col.SetReadonly (true);
  755. return col;
  756. }
  757. protected internal override void CreateChildControls ()
  758. {
  759. CreateControlHierarchy ();
  760. }
  761. protected virtual void CreateControlHierarchy ()
  762. {
  763. styles.Clear ();
  764. wizardTable = new ContainedTable (this);
  765. Table contentTable = wizardTable;
  766. if (DisplaySideBar) {
  767. contentTable = new Table ();
  768. contentTable.CellPadding = 0;
  769. contentTable.CellSpacing = 0;
  770. contentTable.Height = new Unit ("100%");
  771. contentTable.Width = new Unit ("100%");
  772. TableRow row = new TableRow ();
  773. TableCellNamingContainer sideBarCell = new TableCellNamingContainer ();
  774. sideBarCell.ID = "SideBarContainer";
  775. sideBarCell.ControlStyle.Height = Unit.Percentage (100);
  776. CreateSideBar (sideBarCell);
  777. row.Cells.Add (sideBarCell);
  778. TableCell contentCell = new TableCell ();
  779. contentCell.Controls.Add (contentTable);
  780. contentCell.Height = new Unit ("100%");
  781. row.Cells.Add (contentCell);
  782. wizardTable.Rows.Add (row);
  783. }
  784. AddHeaderRow (contentTable);
  785. TableRow viewRow = new TableRow ();
  786. TableCell viewCell = new TableCell ();
  787. customNavigation = null;
  788. multiView = new MultiView ();
  789. foreach (View v in WizardSteps) {
  790. if (v is TemplatedWizardStep)
  791. InstantiateTemplateStep ((TemplatedWizardStep) v);
  792. multiView.Views.Add (v);
  793. }
  794. multiView.ActiveViewIndex = ActiveStepIndex;
  795. RegisterApplyStyle (viewCell, StepStyle);
  796. viewCell.Controls.Add (multiView);
  797. viewRow.Cells.Add (viewCell);
  798. viewRow.Height = new Unit ("100%");
  799. contentTable.Rows.Add (viewRow);
  800. TableRow buttonRow = new TableRow ();
  801. _navigationCell = new TableCell ();
  802. _navigationCell.HorizontalAlign = HorizontalAlign.Right;
  803. RegisterApplyStyle (_navigationCell, NavigationStyle);
  804. CreateButtonBar (_navigationCell);
  805. buttonRow.Cells.Add (_navigationCell);
  806. contentTable.Rows.Add (buttonRow);
  807. Controls.SetReadonly (false);
  808. Controls.Add (wizardTable);
  809. Controls.SetReadonly (true);
  810. }
  811. internal virtual void InstantiateTemplateStep(TemplatedWizardStep step)
  812. {
  813. BaseWizardContainer contentTemplateContainer = new BaseWizardContainer ();
  814. if (step.ContentTemplate != null)
  815. step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
  816. step.ContentTemplateContainer = contentTemplateContainer;
  817. step.Controls.Clear ();
  818. step.Controls.Add (contentTemplateContainer);
  819. BaseWizardNavigationContainer customNavigationTemplateContainer = new BaseWizardNavigationContainer ();
  820. if (step.CustomNavigationTemplate != null) {
  821. step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
  822. RegisterCustomNavigation (step, customNavigationTemplateContainer);
  823. }
  824. step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
  825. }
  826. internal void RegisterCustomNavigation (TemplatedWizardStep step, BaseWizardNavigationContainer customNavigationTemplateContainer) {
  827. if (customNavigation == null)
  828. customNavigation = new Hashtable ();
  829. customNavigation [step] = customNavigationTemplateContainer;
  830. }
  831. void CreateButtonBar (TableCell buttonBarCell)
  832. {
  833. if(customNavigation!=null && customNavigation.Values.Count>0)
  834. {
  835. int i = 0;
  836. foreach (Control customNavigationTemplateContainer in customNavigation.Values) {
  837. customNavigationTemplateContainer.ID = "CustomNavContainer" + i++;
  838. buttonBarCell.Controls.Add (customNavigationTemplateContainer);
  839. }
  840. }
  841. //
  842. // StartNavContainer
  843. //
  844. _startNavContainer = new StartNavigationContainer (this);
  845. _startNavContainer.ID = "StartNavContainer";
  846. if (startNavigationTemplate != null) {
  847. startNavigationTemplate.InstantiateIn (_startNavContainer);
  848. }
  849. else {
  850. TableRow row;
  851. AddNavButtonsTable (_startNavContainer, out row);
  852. AddButtonCell (row, CreateButtonSet (StartNextButtonID, MoveNextCommandName));
  853. AddButtonCell (row, CreateButtonSet (CancelButtonID, CancelCommandName));
  854. _startNavContainer.ConfirmDefaultTemplate ();
  855. }
  856. buttonBarCell.Controls.Add (_startNavContainer);
  857. //
  858. // StepNavContainer
  859. //
  860. _stepNavContainer = new StepNavigationContainer (this);
  861. _stepNavContainer.ID = "StepNavContainer";
  862. if (stepNavigationTemplate != null) {
  863. stepNavigationTemplate.InstantiateIn (_stepNavContainer);
  864. }
  865. else {
  866. TableRow row;
  867. AddNavButtonsTable (_stepNavContainer, out row);
  868. AddButtonCell (row, CreateButtonSet (StepPreviousButtonID, MovePreviousCommandName));
  869. AddButtonCell (row, CreateButtonSet (StepNextButtonID, MoveNextCommandName));
  870. AddButtonCell (row, CreateButtonSet (CancelButtonID, CancelCommandName));
  871. _stepNavContainer.ConfirmDefaultTemplate ();
  872. }
  873. buttonBarCell.Controls.Add (_stepNavContainer);
  874. //
  875. // StepNavContainer
  876. //
  877. _finishNavContainer = new FinishNavigationContainer (this);
  878. _finishNavContainer.ID = "FinishNavContainer";
  879. if (finishNavigationTemplate != null) {
  880. finishNavigationTemplate.InstantiateIn (_finishNavContainer);
  881. }
  882. else {
  883. TableRow row;
  884. AddNavButtonsTable (_finishNavContainer, out row);
  885. AddButtonCell (row, CreateButtonSet (FinishPreviousButtonID, MovePreviousCommandName));
  886. AddButtonCell (row, CreateButtonSet (FinishButtonID, MoveCompleteCommandName));
  887. AddButtonCell (row, CreateButtonSet (CancelButtonID, CancelCommandName));
  888. _finishNavContainer.ConfirmDefaultTemplate ();
  889. }
  890. buttonBarCell.Controls.Add (_finishNavContainer);
  891. }
  892. private static void AddNavButtonsTable (BaseWizardNavigationContainer container, out TableRow row)
  893. {
  894. Table t = new Table ();
  895. t.CellPadding = 5;
  896. t.CellSpacing = 5;
  897. row = new TableRow ();
  898. t.Rows.Add (row);
  899. container.Controls.Add (t);
  900. }
  901. internal Control [] CreateButtonSet (string id, string command)
  902. {
  903. return CreateButtonSet (id, command, true);
  904. }
  905. internal Control [] CreateButtonSet (string id, string command, bool causesValidation)
  906. {
  907. return new Control [] {
  908. CreateButton ( id + ButtonType.Button, command, ButtonType.Button, causesValidation),
  909. CreateButton ( id + ButtonType.Image, command, ButtonType.Image, causesValidation),
  910. CreateButton ( id + ButtonType.Link, command, ButtonType.Link, causesValidation)
  911. };
  912. }
  913. Control CreateButton (string id, string command, ButtonType type, bool causesValidation)
  914. {
  915. WebControl b;
  916. switch (type) {
  917. case ButtonType.Button:
  918. b = CreateStandartButton ();
  919. break;
  920. case ButtonType.Image:
  921. b = CreateImageButton (null);
  922. break;
  923. case ButtonType.Link:
  924. b = CreateLinkButton ();
  925. break;
  926. default:
  927. throw new ArgumentOutOfRangeException ("type");
  928. }
  929. b.ID = id;
  930. b.EnableTheming = false;
  931. ((IButtonControl) b).CommandName = command;
  932. ((IButtonControl) b).ValidationGroup = ID;
  933. ((IButtonControl) b).CausesValidation = causesValidation;
  934. RegisterApplyStyle (b, NavigationButtonStyle);
  935. return b;
  936. }
  937. WebControl CreateStandartButton () {
  938. Button btn = new Button ();
  939. return btn;
  940. }
  941. WebControl CreateImageButton (string imageUrl) {
  942. ImageButton img = new ImageButton ();
  943. img.ImageUrl = imageUrl;
  944. return img;
  945. }
  946. WebControl CreateLinkButton () {
  947. LinkButton link = new LinkButton ();
  948. return link;
  949. }
  950. void AddButtonCell (TableRow row, params Control[] controls)
  951. {
  952. TableCell cell = new TableCell ();
  953. cell.HorizontalAlign = HorizontalAlign.Right;
  954. for (int i = 0; i < controls.Length; i++)
  955. cell.Controls.Add (controls [i]);
  956. row.Cells.Add (cell);
  957. }
  958. void CreateSideBar (TableCell sideBarCell)
  959. {
  960. RegisterApplyStyle (sideBarCell, SideBarStyle);
  961. if (SkipLinkText != "") {
  962. System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
  963. anchor.HRef = "#" + ClientID + "_SkipLink";
  964. Image img = new Image ();
  965. ClientScriptManager csm = new ClientScriptManager (null);
  966. img.ImageUrl = csm.GetWebResourceUrl (typeof (SiteMapPath), "transparent.gif");
  967. img.Attributes.Add ("height", "0");
  968. img.Attributes.Add ("width", "0");
  969. img.AlternateText = SkipLinkText;
  970. anchor.Controls.Add (img);
  971. sideBarCell.Controls.Add (anchor);
  972. }
  973. if (sideBarTemplate != null) {
  974. sideBarTemplate.InstantiateIn (sideBarCell);
  975. stepDatalist = sideBarCell.FindControl (DataListID) as DataList;
  976. if (stepDatalist == null)
  977. throw new InvalidOperationException ("The side bar template must contain a DataList control with id '" + DataListID + "'.");
  978. stepDatalist.ItemDataBound += new DataListItemEventHandler(StepDatalistItemDataBound);
  979. } else {
  980. stepDatalist = new DataList ();
  981. stepDatalist.ID = DataListID;
  982. stepDatalist.SelectedItemStyle.Font.Bold = true;
  983. stepDatalist.ItemTemplate = SideBarItemTemplate;
  984. sideBarCell.Controls.Add (stepDatalist);
  985. }
  986. if (SkipLinkText != "") {
  987. System.Web.UI.HtmlControls.HtmlAnchor anchor = new System.Web.UI.HtmlControls.HtmlAnchor ();
  988. anchor.ID = "SkipLink";
  989. sideBarCell.Controls.Add (anchor);
  990. }
  991. stepDatalist.ItemCommand += new DataListCommandEventHandler (StepDatalistItemCommand);
  992. stepDatalist.CellSpacing = 0;
  993. stepDatalist.DataSource = WizardSteps;
  994. stepDatalist.SelectedIndex = ActiveStepIndex;
  995. stepDatalist.DataBind ();
  996. }
  997. void StepDatalistItemCommand (object sender, DataListCommandEventArgs e)
  998. {
  999. WizardNavigationEventArgs arg = new WizardNavigationEventArgs (ActiveStepIndex, Convert.ToInt32 (e.CommandArgument));
  1000. OnSideBarButtonClick (arg);
  1001. if (!arg.Cancel)
  1002. ActiveStepIndex = arg.NextStepIndex;
  1003. }
  1004. void StepDatalistItemDataBound (object sender, DataListItemEventArgs e)
  1005. {
  1006. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.SelectedItem) {
  1007. IButtonControl button = (IButtonControl) e.Item.FindControl (SideBarButtonID);
  1008. if (button == null)
  1009. 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.");
  1010. WizardStepBase step = (WizardStepBase) e.Item.DataItem;
  1011. if (button is Button)
  1012. ((Button) button).UseSubmitBehavior = false;
  1013. button.CommandName = Wizard.MoveToCommandName;
  1014. button.CommandArgument = WizardSteps.IndexOf (step).ToString ();
  1015. button.Text = step.Name;
  1016. if (step.StepType == WizardStepType.Complete && button is WebControl)
  1017. ((WebControl) button).Enabled = false;
  1018. }
  1019. }
  1020. void AddHeaderRow (Table table)
  1021. {
  1022. TableRow row = new TableRow ();
  1023. _headerCell = new WizardHeaderCell ();
  1024. _headerCell.ID = "HeaderContainer";
  1025. RegisterApplyStyle (_headerCell, HeaderStyle);
  1026. if (headerTemplate != null) {
  1027. headerTemplate.InstantiateIn (_headerCell);
  1028. _headerCell.ConfirmInitState ();
  1029. }
  1030. row.Cells.Add (_headerCell);
  1031. table.Rows.Add (row);
  1032. }
  1033. internal void RegisterApplyStyle (WebControl control, Style style)
  1034. {
  1035. styles.Add (new object [] { control, style });
  1036. }
  1037. protected override Style CreateControlStyle ()
  1038. {
  1039. TableStyle style = new TableStyle ();
  1040. style.CellPadding = 0;
  1041. style.CellSpacing = 0;
  1042. return style;
  1043. }
  1044. protected override IDictionary GetDesignModeState ()
  1045. {
  1046. throw new NotImplementedException ();
  1047. }
  1048. protected internal override void LoadControlState (object ob)
  1049. {
  1050. if (ob == null) return;
  1051. object[] state = (object[]) ob;
  1052. base.LoadControlState (state[0]);
  1053. activeStepIndex = (int) state[1];
  1054. history = (ArrayList) state[2];
  1055. }
  1056. protected internal override object SaveControlState ()
  1057. {
  1058. if (GetHistory ().Count == 0 || (int) history [0] != ActiveStepIndex)
  1059. history.Insert (0, ActiveStepIndex);
  1060. object bstate = base.SaveControlState ();
  1061. return new object[] {
  1062. bstate, activeStepIndex, history
  1063. };
  1064. }
  1065. protected override void LoadViewState (object savedState)
  1066. {
  1067. if (savedState == null) {
  1068. base.LoadViewState (null);
  1069. return;
  1070. }
  1071. object[] states = (object[]) savedState;
  1072. base.LoadViewState (states [0]);
  1073. if (states[1] != null) ((IStateManager)StepStyle).LoadViewState (states[1]);
  1074. if (states[2] != null) ((IStateManager)SideBarStyle).LoadViewState (states[2]);
  1075. if (states[3] != null) ((IStateManager)HeaderStyle).LoadViewState (states[3]);
  1076. if (states[4] != null) ((IStateManager)NavigationStyle).LoadViewState (states[4]);
  1077. if (states[5] != null) ((IStateManager)SideBarButtonStyle).LoadViewState (states[5]);
  1078. if (states[6] != null) ((IStateManager)CancelButtonStyle).LoadViewState (states[6]);
  1079. if (states[7] != null) ((IStateManager)FinishCompleteButtonStyle).LoadViewState (states[7]);
  1080. if (states[8] != null) ((IStateManager)FinishPreviousButtonStyle).LoadViewState (states[8]);
  1081. if (states[9] != null) ((IStateManager)StartNextButtonStyle).LoadViewState (states[9]);
  1082. if (states[10] != null) ((IStateManager)StepNextButtonStyle).LoadViewState (states[10]);
  1083. if (states[11] != null) ((IStateManager)StepPreviousButtonStyle).LoadViewState (states[11]);
  1084. if (states[12] != null) ((IStateManager)NavigationButtonStyle).LoadViewState (states[12]);
  1085. if (states [13] != null)
  1086. ControlStyle.LoadViewState (states [13]);
  1087. }
  1088. protected override object SaveViewState ()
  1089. {
  1090. object [] state = new object [14];
  1091. state [0] = base.SaveViewState ();
  1092. if (stepStyle != null) state [1] = ((IStateManager)stepStyle).SaveViewState ();
  1093. if (sideBarStyle != null) state [2] = ((IStateManager)sideBarStyle).SaveViewState ();
  1094. if (headerStyle != null) state [3] = ((IStateManager)headerStyle).SaveViewState ();
  1095. if (navigationStyle != null) state [4] = ((IStateManager)navigationStyle).SaveViewState ();
  1096. if (sideBarButtonStyle != null) state [5] = ((IStateManager)sideBarButtonStyle).SaveViewState ();
  1097. if (cancelButtonStyle != null) state [6] = ((IStateManager)cancelButtonStyle).SaveViewState ();
  1098. if (finishCompleteButtonStyle != null) state [7] = ((IStateManager)finishCompleteButtonStyle).SaveViewState ();
  1099. if (finishPreviousButtonStyle != null) state [8] = ((IStateManager)finishPreviousButtonStyle).SaveViewState ();
  1100. if (startNextButtonStyle != null) state [9] = ((IStateManager)startNextButtonStyle).SaveViewState ();
  1101. if (stepNextButtonStyle != null) state [10] = ((IStateManager)stepNextButtonStyle).SaveViewState ();
  1102. if (stepPreviousButtonStyle != null) state [11] = ((IStateManager)stepPreviousButtonStyle).SaveViewState ();
  1103. if (navigationButtonStyle != null) state [12] = ((IStateManager)navigationButtonStyle).SaveViewState ();
  1104. if (ControlStyleCreated)
  1105. state [13] = ControlStyle.SaveViewState ();
  1106. for (int n=0; n<state.Length; n++)
  1107. if (state [n] != null) return state;
  1108. return null;
  1109. }
  1110. protected override void TrackViewState ()
  1111. {
  1112. base.TrackViewState();
  1113. if (stepStyle != null) ((IStateManager)stepStyle).TrackViewState();
  1114. if (sideBarStyle != null) ((IStateManager)sideBarStyle).TrackViewState();
  1115. if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
  1116. if (navigationStyle != null) ((IStateManager)navigationStyle).TrackViewState();
  1117. if (sideBarButtonStyle != null) ((IStateManager)sideBarButtonStyle).TrackViewState();
  1118. if (cancelButtonStyle != null) ((IStateManager)cancelButtonStyle).TrackViewState();
  1119. if (finishCompleteButtonStyle != null) ((IStateManager)finishCompleteButtonStyle).TrackViewState();
  1120. if (finishPreviousButtonStyle != null) ((IStateManager)finishPreviousButtonStyle).TrackViewState();
  1121. if (startNextButtonStyle != null) ((IStateManager)startNextButtonStyle).TrackViewState();
  1122. if (stepNextButtonStyle != null) ((IStateManager)stepNextButtonStyle).TrackViewState();
  1123. if (stepPreviousButtonStyle != null) ((IStateManager)stepPreviousButtonStyle).TrackViewState();
  1124. if (navigationButtonStyle != null) ((IStateManager)navigationButtonStyle).TrackViewState();
  1125. if (ControlStyleCreated)
  1126. ControlStyle.TrackViewState ();
  1127. }
  1128. protected internal void RegisterCommandEvents (IButtonControl button)
  1129. {
  1130. button.Command += ProcessCommand;
  1131. }
  1132. void ProcessCommand (object sender, CommandEventArgs args)
  1133. {
  1134. Control c = sender as Control;
  1135. if (c != null) {
  1136. switch (c.ID) {
  1137. case "CancelButton":
  1138. ProcessEvent ("Cancel", null);
  1139. return;
  1140. case "FinishButton":
  1141. ProcessEvent ("MoveComplete", null);
  1142. return;
  1143. case "StepPreviousButton":
  1144. case "FinishPreviousButton":
  1145. ProcessEvent ("MovePrevious", null);
  1146. return;
  1147. case "StartNextButton":
  1148. case "StepNextButton":
  1149. ProcessEvent ("MoveNext", null);
  1150. return;
  1151. }
  1152. }
  1153. ProcessEvent (args.CommandName, args.CommandArgument as string);
  1154. }
  1155. protected override bool OnBubbleEvent (object source, EventArgs e)
  1156. {
  1157. CommandEventArgs args = e as CommandEventArgs;
  1158. if (args != null) {
  1159. ProcessEvent (args.CommandName, args.CommandArgument as string);
  1160. return true;
  1161. }
  1162. return base.OnBubbleEvent (source, e);
  1163. }
  1164. void ProcessEvent (string commandName, string commandArg)
  1165. {
  1166. switch (commandName) {
  1167. case "Cancel":
  1168. if (CancelDestinationPageUrl.Length > 0)
  1169. Context.Response.Redirect (CancelDestinationPageUrl);
  1170. else
  1171. OnCancelButtonClick (EventArgs.Empty);
  1172. break;
  1173. case "MoveComplete":
  1174. int next = -1;
  1175. for (int n=0; n<WizardSteps.Count; n++) {
  1176. if (WizardSteps [n].StepType == WizardStepType.Complete) {
  1177. next = n;
  1178. break;
  1179. }
  1180. }
  1181. if (next == -1 && ActiveStepIndex == WizardSteps.Count - 1)
  1182. next = ActiveStepIndex;
  1183. WizardNavigationEventArgs navArgs = new WizardNavigationEventArgs (ActiveStepIndex, next);
  1184. OnFinishButtonClick (navArgs);
  1185. if (FinishDestinationPageUrl.Length > 0) {
  1186. Context.Response.Redirect (FinishDestinationPageUrl);
  1187. return;
  1188. }
  1189. if (next != -1 && !navArgs.Cancel)
  1190. ActiveStepIndex = next;
  1191. break;
  1192. case "MoveNext":
  1193. if (ActiveStepIndex < WizardSteps.Count - 1) {
  1194. WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex + 1);
  1195. OnNextButtonClick (args);
  1196. if (!args.Cancel)
  1197. ActiveStepIndex++;
  1198. }
  1199. break;
  1200. case "MovePrevious":
  1201. if (ActiveStepIndex > 0) {
  1202. WizardNavigationEventArgs args = new WizardNavigationEventArgs (ActiveStepIndex, ActiveStepIndex - 1);
  1203. OnPreviousButtonClick (args);
  1204. if (!args.Cancel) {
  1205. if (history != null)
  1206. history.Remove (ActiveStepIndex);
  1207. ActiveStepIndex--;
  1208. }
  1209. }
  1210. break;
  1211. case "Move":
  1212. int newb = int.Parse (commandArg);
  1213. ActiveStepIndex = newb;
  1214. break;
  1215. }
  1216. }
  1217. internal void UpdateViews ()
  1218. {
  1219. ChildControlsCreated = false;
  1220. }
  1221. protected internal override void Render (HtmlTextWriter writer)
  1222. {
  1223. PrepareControlHierarchy ();
  1224. wizardTable.Render (writer);
  1225. }
  1226. void PrepareControlHierarchy ()
  1227. {
  1228. // header
  1229. if (!_headerCell.Initialized) {
  1230. if (String.IsNullOrEmpty (HeaderText))
  1231. _headerCell.Parent.Visible = false;
  1232. else
  1233. _headerCell.Text = HeaderText;
  1234. }
  1235. if (ActiveStep.StepType == WizardStepType.Complete)
  1236. _headerCell.Parent.Visible = false;
  1237. // sidebar
  1238. if (stepDatalist != null) {
  1239. stepDatalist.SelectedIndex = ActiveStepIndex;
  1240. stepDatalist.DataBind ();
  1241. if (ActiveStep.StepType == WizardStepType.Complete)
  1242. stepDatalist.NamingContainer.Visible = false;
  1243. }
  1244. // content
  1245. TemplatedWizardStep templateStep = ActiveStep as TemplatedWizardStep;
  1246. if (templateStep != null) {
  1247. BaseWizardContainer contentContainer = templateStep.ContentTemplateContainer as BaseWizardContainer;
  1248. if (contentContainer != null)
  1249. contentContainer.PrepareControlHierarchy ();
  1250. }
  1251. // navigation
  1252. if (customNavigation != null) {
  1253. foreach (Control c in customNavigation.Values)
  1254. c.Visible = false;
  1255. }
  1256. _startNavContainer.Visible = false;
  1257. _stepNavContainer.Visible = false;
  1258. _finishNavContainer.Visible = false;
  1259. BaseWizardNavigationContainer currentNavContainer = GetCurrentNavContainer ();
  1260. if (currentNavContainer == null) {
  1261. _navigationCell.Parent.Visible = false;
  1262. }
  1263. else {
  1264. currentNavContainer.Visible = true;
  1265. currentNavContainer.PrepareControlHierarchy ();
  1266. if (!currentNavContainer.Visible)
  1267. _navigationCell.Parent.Visible = false;
  1268. }
  1269. foreach (object [] styleDef in styles)
  1270. ((WebControl) styleDef [0]).ApplyStyle ((Style) styleDef [1]);
  1271. }
  1272. private BaseWizardNavigationContainer GetCurrentNavContainer ()
  1273. {
  1274. if (customNavigation != null && customNavigation [ActiveStep] != null) {
  1275. return (BaseWizardNavigationContainer) customNavigation [ActiveStep];
  1276. }
  1277. else {
  1278. WizardStepType stepType = GetStepType (ActiveStep, ActiveStepIndex);
  1279. switch (stepType) {
  1280. case WizardStepType.Start:
  1281. return _startNavContainer;
  1282. case WizardStepType.Step:
  1283. return _stepNavContainer;
  1284. case WizardStepType.Finish:
  1285. return _finishNavContainer;
  1286. default:
  1287. return null;
  1288. }
  1289. }
  1290. }
  1291. class TableCellNamingContainer : TableCell, INamingContainer
  1292. {
  1293. public TableCellNamingContainer ()
  1294. {
  1295. SetBindingContainer (false);
  1296. }
  1297. }
  1298. class SideBarButtonTemplate: ITemplate
  1299. {
  1300. Wizard wizard;
  1301. public SideBarButtonTemplate (Wizard wizard)
  1302. {
  1303. this.wizard = wizard;
  1304. }
  1305. public void InstantiateIn (Control control)
  1306. {
  1307. LinkButton b = new LinkButton ();
  1308. wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
  1309. control.Controls.Add (b);
  1310. control.DataBinding += Bound;
  1311. }
  1312. void Bound (object s, EventArgs args)
  1313. {
  1314. WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
  1315. if (step != null) {
  1316. DataListItem c = (DataListItem) s;
  1317. LinkButton b = (LinkButton) c.Controls[0];
  1318. b.ID = SideBarButtonID;
  1319. b.CommandName = Wizard.MoveToCommandName;
  1320. b.CommandArgument = wizard.WizardSteps.IndexOf (step).ToString ();
  1321. b.Text = step.Name;
  1322. if (step.StepType == WizardStepType.Complete)
  1323. b.Enabled = false;
  1324. }
  1325. }
  1326. }
  1327. class WizardHeaderCell : TableCell, INamingContainer
  1328. {
  1329. bool _initialized;
  1330. public bool Initialized {
  1331. get { return _initialized; }
  1332. }
  1333. public WizardHeaderCell ()
  1334. {
  1335. SetBindingContainer (false);
  1336. }
  1337. public void ConfirmInitState ()
  1338. {
  1339. _initialized = true;
  1340. }
  1341. }
  1342. internal abstract class DefaultNavigationContainer : BaseWizardNavigationContainer
  1343. {
  1344. bool _isDefault;
  1345. Wizard _wizard;
  1346. protected Wizard Wizard {
  1347. get { return _wizard; }
  1348. }
  1349. protected DefaultNavigationContainer (Wizard wizard)
  1350. {
  1351. _wizard = wizard;
  1352. }
  1353. public override sealed void PrepareControlHierarchy ()
  1354. {
  1355. if (_isDefault)
  1356. UpdateState ();
  1357. }
  1358. protected abstract void UpdateState ();
  1359. public void ConfirmDefaultTemplate ()
  1360. {
  1361. _isDefault = true;
  1362. }
  1363. protected void UpdateNavButtonState (string id, string text, string image, Style style)
  1364. {
  1365. WebControl b = (WebControl) FindControl (id);
  1366. foreach (Control c in b.Parent.Controls)
  1367. c.Visible = b == c;
  1368. ((IButtonControl) b).Text = text;
  1369. ImageButton imgbtn = b as ImageButton;
  1370. if (imgbtn != null)
  1371. imgbtn.ImageUrl = image;
  1372. b.ApplyStyle (style);
  1373. }
  1374. }
  1375. sealed class StartNavigationContainer : DefaultNavigationContainer
  1376. {
  1377. public StartNavigationContainer (Wizard wizard)
  1378. : base (wizard)
  1379. {
  1380. }
  1381. protected override void UpdateState ()
  1382. {
  1383. bool visible = false;
  1384. // next
  1385. if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex + 1)) {
  1386. visible = true;
  1387. UpdateNavButtonState (Wizard.StartNextButtonID + Wizard.StartNextButtonType, Wizard.StartNextButtonText, Wizard.StartNextButtonImageUrl, Wizard.StartNextButtonStyle);
  1388. }
  1389. else {
  1390. ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
  1391. }
  1392. // cancel
  1393. if (Wizard.DisplayCancelButton) {
  1394. visible = true;
  1395. UpdateNavButtonState (Wizard.CancelButtonID + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
  1396. }
  1397. else {
  1398. ((Table) Controls [0]).Rows [0].Cells [1].Visible = false;
  1399. }
  1400. Visible = visible;
  1401. }
  1402. }
  1403. sealed class StepNavigationContainer : DefaultNavigationContainer
  1404. {
  1405. public StepNavigationContainer (Wizard wizard)
  1406. : base (wizard)
  1407. {
  1408. }
  1409. protected override void UpdateState ()
  1410. {
  1411. bool visible = false;
  1412. // previous
  1413. if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex - 1)) {
  1414. visible = true;
  1415. UpdateNavButtonState (Wizard.StepPreviousButtonID + Wizard.StepPreviousButtonType, Wizard.StepPreviousButtonText, Wizard.StepPreviousButtonImageUrl, Wizard.StepPreviousButtonStyle);
  1416. }
  1417. else {
  1418. ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
  1419. }
  1420. // next
  1421. if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex + 1)) {
  1422. visible = true;
  1423. UpdateNavButtonState (Wizard.StepNextButtonID + Wizard.StepNextButtonType, Wizard.StepNextButtonText, Wizard.StepNextButtonImageUrl, Wizard.StepNextButtonStyle);
  1424. }
  1425. else {
  1426. ((Table) Controls [0]).Rows [0].Cells [1].Visible = false;
  1427. }
  1428. // cancel
  1429. if (Wizard.DisplayCancelButton) {
  1430. visible = true;
  1431. UpdateNavButtonState (Wizard.CancelButtonID + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
  1432. }
  1433. else {
  1434. ((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
  1435. }
  1436. Visible = visible;
  1437. }
  1438. }
  1439. sealed class FinishNavigationContainer : DefaultNavigationContainer
  1440. {
  1441. public FinishNavigationContainer (Wizard wizard)
  1442. : base (wizard)
  1443. {
  1444. }
  1445. protected override void UpdateState ()
  1446. {
  1447. // previous
  1448. if (Wizard.AllowNavigationToStep (Wizard.ActiveStepIndex - 1)) {
  1449. UpdateNavButtonState (Wizard.FinishPreviousButtonID + Wizard.FinishPreviousButtonType, Wizard.FinishPreviousButtonText, Wizard.FinishPreviousButtonImageUrl, Wizard.FinishPreviousButtonStyle);
  1450. }
  1451. else {
  1452. ((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
  1453. }
  1454. // finish
  1455. UpdateNavButtonState (Wizard.FinishButtonID + Wizard.FinishCompleteButtonType, Wizard.FinishCompleteButtonText, Wizard.FinishCompleteButtonImageUrl, Wizard.FinishCompleteButtonStyle);
  1456. // cancel
  1457. if (Wizard.DisplayCancelButton) {
  1458. UpdateNavButtonState (Wizard.CancelButtonID + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
  1459. }
  1460. else {
  1461. ((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
  1462. }
  1463. }
  1464. }
  1465. internal class BaseWizardContainer : Table, INamingContainer
  1466. {
  1467. public TableCell InnerCell {
  1468. get { return Rows [0].Cells [0]; }
  1469. }
  1470. internal BaseWizardContainer ()
  1471. {
  1472. SetBindingContainer (false);
  1473. InitTable ();
  1474. }
  1475. private void InitTable () {
  1476. TableRow row = new TableRow ();
  1477. TableCell cell = new TableCell ();
  1478. cell.ControlStyle.Width = Unit.Percentage (100);
  1479. cell.ControlStyle.Height = Unit.Percentage (100);
  1480. row.Cells.Add (cell);
  1481. this.ControlStyle.Width = Unit.Percentage (100);
  1482. this.ControlStyle.Height = Unit.Percentage (100);
  1483. this.CellPadding = 0;
  1484. this.CellSpacing = 0;
  1485. this.Rows.Add (row);
  1486. }
  1487. public virtual void PrepareControlHierarchy ()
  1488. {
  1489. }
  1490. }
  1491. internal class BaseWizardNavigationContainer : Control, INamingContainer
  1492. {
  1493. internal BaseWizardNavigationContainer ()
  1494. {
  1495. SetBindingContainer (false);
  1496. }
  1497. public virtual void PrepareControlHierarchy ()
  1498. {
  1499. }
  1500. }
  1501. internal abstract class DefaultContentContainer : BaseWizardContainer
  1502. {
  1503. bool _isDefault;
  1504. Wizard _wizard;
  1505. protected bool IsDefaultTemplate {
  1506. get { return _isDefault; }
  1507. }
  1508. protected Wizard Wizard {
  1509. get { return _wizard; }
  1510. }
  1511. protected DefaultContentContainer (Wizard wizard)
  1512. {
  1513. _wizard = wizard;
  1514. }
  1515. public override sealed void PrepareControlHierarchy ()
  1516. {
  1517. if (_isDefault)
  1518. UpdateState ();
  1519. }
  1520. protected abstract void UpdateState ();
  1521. public void ConfirmDefaultTemplate ()
  1522. {
  1523. _isDefault = true;
  1524. }
  1525. }
  1526. }
  1527. }
  1528. #endif