Control.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. //
  2. // System.Web.UI.Control.cs
  3. //
  4. // Authors:
  5. // Bob Smith <[email protected]>
  6. // Gonzalo Paniagua Javier ([email protected]
  7. // Andreas Nahr ([email protected])
  8. //
  9. // (C) Bob Smith
  10. // (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
  11. //
  12. using System;
  13. using System.Collections;
  14. using System.ComponentModel;
  15. using System.ComponentModel.Design;
  16. using System.ComponentModel.Design.Serialization;
  17. using System.Web;
  18. using System.Web.Util;
  19. namespace System.Web.UI
  20. {
  21. [DefaultProperty ("ID"), DesignerCategory ("Code"), ToolboxItemFilter ("System.Web.UI", ToolboxItemFilterType.Require)]
  22. [ToolboxItem ("System.Web.UI.Design.WebControlToolboxItem, " + Consts.AssemblySystem_Design)]
  23. [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
  24. [DesignerSerializer ("Microsoft.VSDesigner.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  25. public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
  26. {
  27. private static readonly object DataBindingEvent = new object();
  28. private static readonly object DisposedEvent = new object();
  29. private static readonly object InitEvent = new object();
  30. private static readonly object LoadEvent = new object();
  31. private static readonly object PreRenderEvent = new object();
  32. private static readonly object UnloadEvent = new object();
  33. private string uniqueID;
  34. private string _userId = null;
  35. private string _cachedClientId = null;
  36. private ControlCollection _controls = null;
  37. private bool _enableViewState = true;
  38. private IDictionary _childViewStates = null; //TODO: Not sure datatype. Placeholder guess.
  39. private bool _isNamingContainer = false;
  40. private Control _namingContainer = null;
  41. private Page _page = null;
  42. private Control _parent = null;
  43. private ISite _site = null;
  44. private bool _visible = true;
  45. private HttpContext _context = null;
  46. private bool _childControlsCreated = false;
  47. private StateBag _viewState = null;
  48. private bool _trackViewState = false;
  49. private EventHandlerList _events = new EventHandlerList();
  50. private RenderMethod _renderMethodDelegate = null;
  51. private bool autoID = true;
  52. private bool creatingControls = false;
  53. private bool bindingContainer = true;
  54. private bool autoEventWireup = true;
  55. bool inited = false;
  56. bool viewStateLoaded;
  57. bool loaded = false;
  58. bool prerendered = false;
  59. int defaultNumberID = 0;
  60. private DataBindingCollection dataBindings = null;
  61. Hashtable pendingVS; // may hold unused viewstate data from child controls
  62. public Control()
  63. {
  64. if (this is INamingContainer) _isNamingContainer = true;
  65. }
  66. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  67. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  68. public Control BindingContainer
  69. {
  70. get {
  71. Control container = NamingContainer;
  72. if (!container.bindingContainer)
  73. container = container.BindingContainer;
  74. return container;
  75. }
  76. }
  77. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  78. [Browsable (false)]
  79. [WebSysDescription ("An Identification of the control that is rendered.")]
  80. public virtual string ClientID {
  81. get {
  82. string client = UniqueID;
  83. if (client != null)
  84. client = client.Replace (':', '_');
  85. return client;
  86. }
  87. }
  88. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  89. [Browsable (false)]
  90. [WebSysDescription ("The child controls of this control.")]
  91. public virtual ControlCollection Controls //DIT
  92. {
  93. get
  94. {
  95. if (_controls == null) _controls = CreateControlCollection();
  96. return _controls;
  97. }
  98. }
  99. [DefaultValue (true), WebCategory ("FIXME")]
  100. [WebSysDescription ("An Identification of the control that is rendered.")]
  101. public virtual bool EnableViewState //DIT
  102. {
  103. get
  104. {
  105. return _enableViewState;
  106. }
  107. set
  108. {
  109. _enableViewState = value;
  110. }
  111. }
  112. [MergableProperty (false), ParenthesizePropertyName (true)]
  113. [WebSysDescription ("The name of the control that is rendered.")]
  114. public virtual string ID {
  115. get {
  116. return _userId;
  117. }
  118. set {
  119. if (value == "")
  120. value = null;
  121. _userId = value;
  122. NullifyUniqueID ();
  123. }
  124. }
  125. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  126. [Browsable (false)]
  127. [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
  128. public virtual Control NamingContainer //DIT
  129. {
  130. get
  131. {
  132. if (_namingContainer == null && _parent != null)
  133. {
  134. if (_parent._isNamingContainer == false)
  135. _namingContainer = _parent.NamingContainer;
  136. else
  137. _namingContainer = _parent;
  138. }
  139. return _namingContainer;
  140. }
  141. }
  142. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  143. [Browsable (false)]
  144. [WebSysDescription ("The webpage that this control resides on.")]
  145. public virtual Page Page //DIT
  146. {
  147. get
  148. {
  149. if (_page == null && _parent != null) _page = _parent.Page;
  150. return _page;
  151. }
  152. set
  153. {
  154. _page = value;
  155. }
  156. }
  157. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  158. [Browsable (false)]
  159. [WebSysDescription ("The parent control of this control.")]
  160. public virtual Control Parent //DIT
  161. {
  162. get
  163. {
  164. return _parent;
  165. }
  166. }
  167. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  168. [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
  169. [WebSysDescription ("The site this control is part of.")]
  170. public ISite Site //DIT
  171. {
  172. get
  173. {
  174. return _site;
  175. }
  176. set
  177. {
  178. _site = value;
  179. }
  180. }
  181. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  182. [Browsable (false)]
  183. [WebSysDescription ("A virtual directory containing the parent of the control.")]
  184. public virtual string TemplateSourceDirectory {
  185. get { return (_parent == null) ? String.Empty : _parent.TemplateSourceDirectory; }
  186. }
  187. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  188. [Browsable (false)]
  189. [WebSysDescription ("The unique ID of the control.")]
  190. public virtual string UniqueID {
  191. get {
  192. if (uniqueID != null)
  193. return uniqueID;
  194. if (_namingContainer == null) {
  195. return _userId;
  196. }
  197. if (_userId == null)
  198. _userId = _namingContainer.GetDefaultName ();
  199. string prefix = _namingContainer.UniqueID;
  200. if (_namingContainer == _page || prefix == null) {
  201. uniqueID = _userId;
  202. return uniqueID;
  203. }
  204. uniqueID = prefix + ":" + _userId;
  205. return uniqueID;
  206. }
  207. }
  208. [DefaultValue (true), Bindable (true), WebCategory ("FIXME")]
  209. [WebSysDescription ("Visiblity state of the control.")]
  210. public virtual bool Visible {
  211. get {
  212. if (_visible == false)
  213. return false;
  214. if (_parent != null)
  215. return _parent.Visible;
  216. return true;
  217. }
  218. set {
  219. if (value != _visible)
  220. ViewState ["Visible"] = value;
  221. _visible = value;
  222. }
  223. }
  224. protected bool ChildControlsCreated //DIT
  225. {
  226. get
  227. {
  228. return _childControlsCreated;
  229. }
  230. set
  231. {
  232. if (value == false && _childControlsCreated == true)
  233. _controls.Clear();
  234. _childControlsCreated = value;
  235. }
  236. }
  237. protected virtual HttpContext Context //DIT
  238. {
  239. get
  240. {
  241. HttpContext context;
  242. if (_context != null)
  243. return _context;
  244. if (_parent == null)
  245. return HttpContext.Current;
  246. context = _parent.Context;
  247. if (context != null)
  248. return context;
  249. return HttpContext.Current;
  250. }
  251. }
  252. protected EventHandlerList Events //DIT
  253. {
  254. get
  255. {
  256. if (_events == null)
  257. {
  258. _events = new EventHandlerList();
  259. }
  260. return _events;
  261. }
  262. }
  263. protected bool HasChildViewState //DIT
  264. {
  265. get
  266. {
  267. if (_childViewStates == null) return false;
  268. return true;
  269. }
  270. }
  271. protected bool IsTrackingViewState //DIT
  272. {
  273. get
  274. {
  275. return _trackViewState;
  276. }
  277. }
  278. protected virtual StateBag ViewState
  279. {
  280. get
  281. {
  282. if(_viewState == null)
  283. _viewState = new StateBag (ViewStateIgnoresCase);
  284. if (IsTrackingViewState)
  285. _viewState.TrackViewState ();
  286. return _viewState;
  287. }
  288. }
  289. protected virtual bool ViewStateIgnoresCase
  290. {
  291. get {
  292. return false;
  293. }
  294. }
  295. internal bool AutoEventWireup {
  296. get { return autoEventWireup; }
  297. set { autoEventWireup = value; }
  298. }
  299. internal void SetBindingContainer (bool isBC)
  300. {
  301. bindingContainer = isBC;
  302. }
  303. internal void ResetChildNames ()
  304. {
  305. defaultNumberID = 0;
  306. }
  307. string GetDefaultName ()
  308. {
  309. return "_ctrl" + defaultNumberID++;
  310. }
  311. void NullifyUniqueID ()
  312. {
  313. uniqueID = null;
  314. if (_controls == null)
  315. return;
  316. foreach (Control c in _controls)
  317. c.NullifyUniqueID ();
  318. }
  319. protected internal virtual void AddedControl (Control control, int index)
  320. {
  321. /* Ensure the control don't have more than 1 parent */
  322. if (control._parent != null)
  323. control._parent.Controls.Remove (control);
  324. control._parent = this;
  325. control._page = _page;
  326. Control nc = _isNamingContainer ? this : NamingContainer;
  327. if (nc != null) {
  328. control._namingContainer = nc;
  329. if (control.AutoID == true && control._userId == null)
  330. control._userId = nc.GetDefaultName () + "a";
  331. }
  332. if (inited)
  333. control.InitRecursive (nc);
  334. if (viewStateLoaded || loaded) {
  335. if (pendingVS != null) {
  336. object vs = pendingVS [index];
  337. if (vs != null) {
  338. pendingVS.Remove (index);
  339. if (pendingVS.Count == 0)
  340. pendingVS = null;
  341. control.LoadViewStateRecursive (vs);
  342. }
  343. }
  344. }
  345. if (loaded)
  346. control.LoadRecursive ();
  347. if (prerendered)
  348. control.PreRenderRecursiveInternal ();
  349. }
  350. protected virtual void AddParsedSubObject(object obj) //DIT
  351. {
  352. WebTrace.PushContext ("Control.AddParsedSubobject ()");
  353. Control c = obj as Control;
  354. WebTrace.WriteLine ("Start: {0} -> {1}", obj, (c != null) ? c.ID : String.Empty);
  355. if (c != null) Controls.Add(c);
  356. WebTrace.WriteLine ("End");
  357. WebTrace.PopContext ();
  358. }
  359. protected void BuildProfileTree(string parentId, bool calcViewState)
  360. {
  361. //TODO
  362. }
  363. protected void ClearChildViewState ()
  364. {
  365. pendingVS = null;
  366. }
  367. protected virtual void CreateChildControls() {} //DIT
  368. protected virtual ControlCollection CreateControlCollection() //DIT
  369. {
  370. return new ControlCollection(this);
  371. }
  372. protected virtual void EnsureChildControls () //DIT
  373. {
  374. if (ChildControlsCreated == false && !creatingControls) {
  375. creatingControls = true;
  376. CreateChildControls();
  377. ChildControlsCreated = true;
  378. creatingControls = false;
  379. }
  380. }
  381. protected bool IsLiteralContent()
  382. {
  383. if (_controls != null)
  384. if (_controls.Count == 1)
  385. if (_controls[0] is LiteralControl)
  386. return true;
  387. return false;
  388. }
  389. public virtual Control FindControl (string id)
  390. {
  391. return FindControl (id, 0);
  392. }
  393. Control LookForControlByName (string id)
  394. {
  395. if (!HasChildren)
  396. return null;
  397. foreach (Control c in _controls) {
  398. if (String.Compare (id, c._userId, true) == 0)
  399. return c;
  400. if (!c._isNamingContainer && c.HasChildren) {
  401. Control child = c.LookForControlByName (id);
  402. if (child != null)
  403. return child;
  404. }
  405. }
  406. return null;
  407. }
  408. protected virtual Control FindControl (string id, int pathOffset)
  409. {
  410. EnsureChildControls ();
  411. if (_controls == null)
  412. return null;
  413. Control namingContainer = null;
  414. if (!_isNamingContainer) {
  415. namingContainer = NamingContainer;
  416. if (namingContainer == null)
  417. return null;
  418. return namingContainer.FindControl (id, pathOffset);
  419. }
  420. int colon = id.IndexOf (':', pathOffset);
  421. if (colon == -1)
  422. return LookForControlByName (id.Substring (pathOffset));
  423. string idfound = id.Substring (pathOffset, colon - pathOffset);
  424. namingContainer = LookForControlByName (idfound);
  425. if (namingContainer == null)
  426. return null;
  427. return namingContainer.FindControl (id, colon + 1);
  428. }
  429. protected virtual void LoadViewState(object savedState)
  430. {
  431. if (savedState != null) {
  432. ViewState.LoadViewState (savedState);
  433. object o = ViewState ["Visible"];
  434. if (o != null)
  435. _visible = (bool) o;
  436. }
  437. }
  438. [MonoTODO("Secure?")]
  439. protected string MapPathSecure(string virtualPath)
  440. {
  441. string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
  442. return Context.Request.MapPath (combined);
  443. }
  444. protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
  445. {
  446. return false;
  447. }
  448. protected virtual void OnDataBinding(EventArgs e) //DIT
  449. {
  450. if (_events != null)
  451. {
  452. EventHandler eh = (EventHandler)(_events[DataBindingEvent]);
  453. if (eh != null) eh(this, e);
  454. }
  455. }
  456. protected virtual void OnInit(EventArgs e) //DIT
  457. {
  458. if (_events != null)
  459. {
  460. EventHandler eh = (EventHandler)(_events[InitEvent]);
  461. if (eh != null) eh(this, e);
  462. }
  463. }
  464. protected virtual void OnLoad(EventArgs e) //DIT
  465. {
  466. if (_events != null)
  467. {
  468. EventHandler eh = (EventHandler)(_events[LoadEvent]);
  469. if (eh != null) eh(this, e);
  470. }
  471. }
  472. protected virtual void OnPreRender(EventArgs e) //DIT
  473. {
  474. if (_events != null)
  475. {
  476. EventHandler eh = (EventHandler)(_events[PreRenderEvent]);
  477. if (eh != null) eh(this, e);
  478. }
  479. }
  480. protected virtual void OnUnload(EventArgs e) //DIT
  481. {
  482. if (_events != null)
  483. {
  484. EventHandler eh = (EventHandler)(_events[UnloadEvent]);
  485. if (eh != null) eh(this, e);
  486. }
  487. }
  488. protected void RaiseBubbleEvent(object source, EventArgs args)
  489. {
  490. Control c = Parent;
  491. while (c != null) {
  492. if (c.OnBubbleEvent (source, args))
  493. break;
  494. c = c.Parent;
  495. }
  496. }
  497. protected virtual void Render(HtmlTextWriter writer) //DIT
  498. {
  499. RenderChildren(writer);
  500. }
  501. protected virtual void RenderChildren(HtmlTextWriter writer) //DIT
  502. {
  503. if (_renderMethodDelegate != null)
  504. _renderMethodDelegate(writer, this);
  505. else if (_controls != null)
  506. foreach (Control c in _controls)
  507. c.RenderControl(writer);
  508. }
  509. protected virtual object SaveViewState ()
  510. {
  511. if (_viewState == null)
  512. return null;
  513. return _viewState.SaveViewState ();
  514. }
  515. protected virtual void TrackViewState()
  516. {
  517. if (_viewState != null)
  518. _viewState.TrackViewState ();
  519. _trackViewState = true;
  520. }
  521. public virtual void Dispose()
  522. {
  523. if (_events != null)
  524. {
  525. EventHandler eh = (EventHandler) _events [DisposedEvent];
  526. if (eh != null)
  527. eh(this, EventArgs.Empty);
  528. }
  529. }
  530. internal bool HasChildren
  531. {
  532. get { return (_controls != null && _controls.Count > 0); }
  533. }
  534. [WebCategory ("FIXME")]
  535. [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
  536. public event EventHandler DataBinding //DIT
  537. {
  538. add
  539. {
  540. Events.AddHandler(DataBindingEvent, value);
  541. }
  542. remove
  543. {
  544. Events.RemoveHandler(DataBindingEvent, value);
  545. }
  546. }
  547. [WebSysDescription ("Raised when the contol is disposed.")]
  548. public event EventHandler Disposed //DIT
  549. {
  550. add
  551. {
  552. Events.AddHandler(DisposedEvent, value);
  553. }
  554. remove
  555. {
  556. Events.RemoveHandler(DisposedEvent, value);
  557. }
  558. }
  559. [WebSysDescription ("Raised when the page containing the control is initialized.")]
  560. public event EventHandler Init //DIT
  561. {
  562. add
  563. {
  564. Events.AddHandler(InitEvent, value);
  565. }
  566. remove
  567. {
  568. Events.RemoveHandler(InitEvent, value);
  569. }
  570. }
  571. [WebSysDescription ("Raised after the page containing the control has been loaded.")]
  572. public event EventHandler Load //DIT
  573. {
  574. add
  575. {
  576. Events.AddHandler(LoadEvent, value);
  577. }
  578. remove
  579. {
  580. Events.RemoveHandler(LoadEvent, value);
  581. }
  582. }
  583. [WebSysDescription ("Raised before the page containing the control is rendered.")]
  584. public event EventHandler PreRender //DIT
  585. {
  586. add
  587. {
  588. Events.AddHandler(PreRenderEvent, value);
  589. }
  590. remove
  591. {
  592. Events.RemoveHandler(PreRenderEvent, value);
  593. }
  594. }
  595. [WebSysDescription ("Raised when the page containing the control is unloaded.")]
  596. public event EventHandler Unload //DIT
  597. {
  598. add
  599. {
  600. Events.AddHandler(UnloadEvent, value);
  601. }
  602. remove
  603. {
  604. Events.RemoveHandler(UnloadEvent, value);
  605. }
  606. }
  607. public virtual void DataBind() //DIT
  608. {
  609. OnDataBinding(EventArgs.Empty);
  610. if (_controls != null)
  611. foreach (Control c in _controls)
  612. c.DataBind();
  613. }
  614. public virtual bool HasControls() //DIT
  615. {
  616. if (_controls != null && _controls.Count >0) return true;
  617. return false;
  618. }
  619. public void RenderControl(HtmlTextWriter writer)
  620. {
  621. if (_visible)
  622. Render(writer);
  623. }
  624. public string ResolveUrl(string relativeUrl)
  625. {
  626. if (relativeUrl == null)
  627. throw new ArgumentNullException ("relativeUrl");
  628. if (relativeUrl == "")
  629. return "";
  630. string ts = TemplateSourceDirectory;
  631. if (UrlUtils.IsRelativeUrl (relativeUrl) == false || ts == "")
  632. return relativeUrl;
  633. HttpResponse resp = Context.Response;
  634. return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
  635. }
  636. [EditorBrowsable (EditorBrowsableState.Advanced)]
  637. public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
  638. {
  639. _renderMethodDelegate = renderMethod;
  640. }
  641. internal void LoadRecursive()
  642. {
  643. OnLoad (EventArgs.Empty);
  644. if (_controls != null) {
  645. foreach (Control c in _controls)
  646. c.LoadRecursive ();
  647. }
  648. loaded = true;
  649. }
  650. internal void UnloadRecursive(Boolean dispose)
  651. {
  652. if (_controls != null) {
  653. foreach (Control c in _controls)
  654. c.UnloadRecursive (dispose);
  655. }
  656. OnUnload (EventArgs.Empty);
  657. if (dispose)
  658. Dispose();
  659. }
  660. internal void PreRenderRecursiveInternal()
  661. {
  662. if (_visible) {
  663. EnsureChildControls ();
  664. OnPreRender (EventArgs.Empty);
  665. if (_controls == null)
  666. return;
  667. foreach (Control c in _controls)
  668. c.PreRenderRecursiveInternal ();
  669. }
  670. prerendered = true;
  671. }
  672. internal void InitRecursive(Control namingContainer)
  673. {
  674. if (_controls != null) {
  675. if (_isNamingContainer)
  676. namingContainer = this;
  677. if (namingContainer != null &&
  678. namingContainer._userId == null &&
  679. namingContainer.autoID)
  680. namingContainer._userId = namingContainer.GetDefaultName () + "b";
  681. foreach (Control c in _controls) {
  682. c._page = Page;
  683. c._namingContainer = namingContainer;
  684. if (namingContainer != null && c._userId == null && c.autoID)
  685. c._userId = namingContainer.GetDefaultName () + "c";
  686. c.InitRecursive (namingContainer);
  687. }
  688. }
  689. OnInit (EventArgs.Empty);
  690. TrackViewState ();
  691. inited = true;
  692. }
  693. internal object SaveViewStateRecursive ()
  694. {
  695. if (!EnableViewState)
  696. return null;
  697. ArrayList controlList = null;
  698. ArrayList controlStates = null;
  699. int idx = -1;
  700. foreach (Control ctrl in Controls) {
  701. object ctrlState = ctrl.SaveViewStateRecursive ();
  702. idx++;
  703. if (ctrlState == null)
  704. continue;
  705. if (controlList == null) {
  706. controlList = new ArrayList ();
  707. controlStates = new ArrayList ();
  708. }
  709. controlList.Add (idx);
  710. controlStates.Add (ctrlState);
  711. }
  712. object thisState = SaveViewState ();
  713. if (thisState == null && controlList == null && controlStates == null)
  714. return null;
  715. return new Triplet (thisState, controlList, controlStates);
  716. }
  717. internal void LoadViewStateRecursive (object savedState)
  718. {
  719. if (!EnableViewState || savedState == null)
  720. return;
  721. Triplet savedInfo = (Triplet) savedState;
  722. LoadViewState (savedInfo.First);
  723. ArrayList controlList = savedInfo.Second as ArrayList;
  724. if (controlList == null)
  725. return;
  726. ArrayList controlStates = savedInfo.Third as ArrayList;
  727. int nControls = controlList.Count;
  728. for (int i = 0; i < nControls; i++) {
  729. int k = (int) controlList [i];
  730. if (k < Controls.Count && controlStates != null) {
  731. Control c = Controls [k];
  732. c.LoadViewStateRecursive (controlStates [i]);
  733. } else {
  734. if (pendingVS == null)
  735. pendingVS = new Hashtable ();
  736. pendingVS [k] = controlStates [i];
  737. }
  738. }
  739. viewStateLoaded = true;
  740. }
  741. void IParserAccessor.AddParsedSubObject(object obj)
  742. {
  743. AddParsedSubObject(obj);
  744. }
  745. DataBindingCollection IDataBindingsAccessor.DataBindings
  746. {
  747. get
  748. {
  749. if(dataBindings == null)
  750. dataBindings = new DataBindingCollection();
  751. return dataBindings;
  752. }
  753. }
  754. bool IDataBindingsAccessor.HasDataBindings
  755. {
  756. get
  757. {
  758. return (dataBindings!=null && dataBindings.Count>0);
  759. }
  760. }
  761. internal bool AutoID
  762. {
  763. get { return autoID; }
  764. set {
  765. if (value == false && _isNamingContainer)
  766. return;
  767. autoID = value;
  768. }
  769. }
  770. internal void PreventAutoID()
  771. {
  772. AutoID = false;
  773. }
  774. protected internal virtual void RemovedControl (Control control)
  775. {
  776. control.UnloadRecursive (false);
  777. control._parent = null;
  778. control._page = null;
  779. control._namingContainer = null;
  780. }
  781. //TODO: I think there are some needed Interface implementations to do here.
  782. }
  783. }