Control.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. //
  2. // System.Web.UI.Control.cs
  3. //
  4. // Authors:
  5. // Bob Smith <[email protected]>
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (C) Bob Smith
  9. // (c) 2002 Ximian, Inc. (http://www.ximian.com)
  10. //
  11. /*
  12. * Maintainer: [email protected], [email protected]
  13. * (C) Bob Smith, Gaurav Vaish
  14. */
  15. //notes: view state only tracks changes after OnInit method is executed for the page request. You can read from it at any time, but cant write to it during rendering.
  16. //even more notes: view state info in trackviewstate method description. read later.
  17. //Ok, enough notes: what the heck is different between enable view state, and track view state.
  18. //Well, maybe not. How does the ViewState know when to track changes? Does it look at the property
  19. //on the owning control, or does it have a method/property of its own that gets called?
  20. // I think this last question is solved in the Interface for it. Look into this.
  21. //cycle:
  22. //init is called when control is first created.
  23. //load view state ic called right after init to populate the view state.
  24. //loadpostdata is called if ipostbackdatahandler is implemented.
  25. //load is called when control is loaded into a page
  26. //raisepostdatachangedevent if ipostbackdatahandler is implemented.
  27. //raisepostbackevent if ipostbackeventhandler is implemented.
  28. //prerender is called when the server is about to render its page object
  29. //SaveViewState is called.
  30. //Unload then dispose it apears. :)
  31. //Naming Container MUST have some methods. What are they? No clue. Help? (updated: the doc says that it's just a marker interface)
  32. //read this later. http://gotdotnet.com/quickstart/aspplus/
  33. //This to: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpconattributesdesign-timesupport.asp
  34. //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguidnf/html/cpcontracefunctionality.asp
  35. // Isnt life grand? :)
  36. // See the undocumented methods? Gota love um. ;)
  37. // ASP.test4_aspx.Page_Load(Object Sender, EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
  38. // System.Web.UI.Control.OnLoad(EventArgs e) +67
  39. // System.Web.UI.Control.LoadRecursive() +73
  40. // System.Web.UI.Page.ProcessRequestMain() +394
  41. // ASP.test4_aspx.Page_Unload(Object Sender, EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
  42. // System.EventHandler.Invoke(Object sender, EventArgs e) +0
  43. // System.Web.UI.Control.OnUnload(EventArgs e) +67
  44. // System.Web.UI.Control.UnloadRecursive(Boolean dispose) +78
  45. // System.Web.UI.Page.ProcessRequest() +194
  46. // System.Web.UI.Page.ProcessRequest(HttpContext context) +18
  47. // System.Web.CallHandlerExecutionStep.Execute() +179
  48. // System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87
  49. // ASP.test4_aspx.Page_Unload(Object Sender, EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
  50. // System.Web.UI.Control.OnUnload(EventArgs e) +67
  51. // System.Web.UI.Control.UnloadRecursive(Boolean dispose) +78
  52. // System.Web.UI.Page.ProcessRequest()
  53. // ASP.test4_aspx.Page_Kill(Object Sender, EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
  54. // System.Web.UI.Control.OnPreRender(EventArgs e) +67
  55. // System.Web.UI.Control.PreRenderRecursiveInternal() +61
  56. // System.Web.UI.Page.ProcessRequestMain() +753
  57. // ASP.test4_aspx.OnInit(EventArgs e) in \\genfs2\www24\bobsmith11\test4.aspx:6
  58. // System.Web.UI.Control.InitRecursive(Control namingContainer) +202
  59. // System.Web.UI.Page.ProcessRequestMain() +120
  60. // ASP.test4_aspx.SaveViewState() in \\genfs2\www24\bobsmith11\test4.aspx:12
  61. // System.Web.UI.Control.SaveViewStateRecursive() +51
  62. // System.Web.UI.Page.SavePageViewState() +174
  63. // System.Web.UI.Page.ProcessRequestMain() +861
  64. // ASP.test_aspx.LoadViewState(Object t) +28
  65. // System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +125
  66. // System.Web.UI.Page.LoadPageViewState() +182
  67. // System.Web.UI.Page.ProcessRequestMain() +256
  68. using System;
  69. using System.Collections;
  70. using System.ComponentModel;
  71. using System.Web;
  72. using System.Web.Util;
  73. namespace System.Web.UI
  74. {
  75. public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
  76. {
  77. private static readonly object DataBindingEvent = new object();
  78. private static readonly object DisposedEvent = new object();
  79. private static readonly object InitEvent = new object();
  80. private static readonly object LoadEvent = new object();
  81. private static readonly object PreRenderEvent = new object();
  82. private static readonly object UnloadEvent = new object();
  83. private string uniqueID;
  84. private string _userId = null;
  85. private string _cachedClientId = null;
  86. private ControlCollection _controls = null;
  87. private bool _enableViewState = true;
  88. private IDictionary _childViewStates = null; //TODO: Not sure datatype. Placeholder guess.
  89. private bool _isNamingContainer = false;
  90. private Control _namingContainer = null;
  91. private Page _page = null;
  92. private Control _parent = null;
  93. private ISite _site = null;
  94. private bool _visible = true;
  95. private HttpContext _context = null;
  96. private bool _childControlsCreated = false;
  97. private StateBag _viewState = null;
  98. private bool _trackViewState = false;
  99. private EventHandlerList _events = new EventHandlerList();
  100. private RenderMethod _renderMethodDelegate = null;
  101. private bool autoID = true;
  102. private bool creatingControls = false;
  103. private bool bindingContainer = true;
  104. private bool autoEventWireup = true;
  105. bool inited = false;
  106. bool loaded = false;
  107. bool prerendered = false;
  108. int defaultNumberID = 0;
  109. private DataBindingCollection dataBindings = null;
  110. public Control()
  111. {
  112. if (this is INamingContainer) _isNamingContainer = true;
  113. }
  114. public Control BindingContainer
  115. {
  116. get {
  117. Control container = NamingContainer;
  118. if (!container.bindingContainer)
  119. container = container.BindingContainer;
  120. return container;
  121. }
  122. }
  123. public virtual string ClientID {
  124. get {
  125. string client = UniqueID;
  126. if (client != null)
  127. client = client.Replace (':', '_');
  128. return client;
  129. }
  130. }
  131. public virtual ControlCollection Controls //DIT
  132. {
  133. get
  134. {
  135. if (_controls == null) _controls = CreateControlCollection();
  136. return _controls;
  137. }
  138. }
  139. public virtual bool EnableViewState //DIT
  140. {
  141. get
  142. {
  143. return _enableViewState;
  144. }
  145. set
  146. {
  147. _enableViewState = value;
  148. }
  149. }
  150. public virtual string ID {
  151. get {
  152. return _userId;
  153. }
  154. set {
  155. if (value == "")
  156. value = null;
  157. _userId = value;
  158. NullifyUniqueID ();
  159. }
  160. }
  161. public virtual Control NamingContainer //DIT
  162. {
  163. get
  164. {
  165. if (_namingContainer == null && _parent != null)
  166. {
  167. if (_parent._isNamingContainer == false)
  168. _namingContainer = _parent.NamingContainer;
  169. else
  170. _namingContainer = _parent;
  171. }
  172. return _namingContainer;
  173. }
  174. }
  175. public virtual Page Page //DIT
  176. {
  177. get
  178. {
  179. if (_page == null && _parent != null) _page = _parent.Page;
  180. return _page;
  181. }
  182. set
  183. {
  184. _page = value;
  185. }
  186. }
  187. public virtual Control Parent //DIT
  188. {
  189. get
  190. {
  191. return _parent;
  192. }
  193. }
  194. public ISite Site //DIT
  195. {
  196. get
  197. {
  198. return _site;
  199. }
  200. set
  201. {
  202. _site = value;
  203. }
  204. }
  205. public virtual string TemplateSourceDirectory {
  206. get { return (_parent == null) ? String.Empty : _parent.TemplateSourceDirectory; }
  207. }
  208. public virtual string UniqueID {
  209. get {
  210. if (uniqueID != null)
  211. return uniqueID;
  212. if (_namingContainer == null) {
  213. return _userId;
  214. }
  215. if (_userId == null)
  216. _userId = "_uniqueIDctrl" + _namingContainer.defaultNumberID++;
  217. string prefix = _namingContainer.UniqueID;
  218. if (_namingContainer == _page || prefix == null) {
  219. uniqueID = _userId;
  220. return uniqueID;
  221. }
  222. uniqueID = prefix + ":" + _userId;
  223. return uniqueID;
  224. }
  225. }
  226. public virtual bool Visible
  227. {
  228. get
  229. {
  230. if (_visible == false)
  231. return false;
  232. if (_parent != null)
  233. return _parent.Visible;
  234. return true;
  235. }
  236. set
  237. {
  238. _visible = value;
  239. }
  240. }
  241. protected bool ChildControlsCreated //DIT
  242. {
  243. get
  244. {
  245. return _childControlsCreated;
  246. }
  247. set
  248. {
  249. if (value == false && _childControlsCreated == true)
  250. _controls.Clear();
  251. _childControlsCreated = value;
  252. }
  253. }
  254. protected virtual HttpContext Context //DIT
  255. {
  256. get
  257. {
  258. HttpContext context;
  259. if (_context != null)
  260. return _context;
  261. if (_parent == null)
  262. return HttpContext.Current;
  263. context = _parent.Context;
  264. if (context != null)
  265. return context;
  266. return HttpContext.Current;
  267. }
  268. }
  269. protected EventHandlerList Events //DIT
  270. {
  271. get
  272. {
  273. if (_events == null)
  274. {
  275. _events = new EventHandlerList();
  276. }
  277. return _events;
  278. }
  279. }
  280. protected bool HasChildViewState //DIT
  281. {
  282. get
  283. {
  284. if (_childViewStates == null) return false;
  285. return true;
  286. }
  287. }
  288. protected bool IsTrackingViewState //DIT
  289. {
  290. get
  291. {
  292. return _trackViewState;
  293. }
  294. }
  295. protected virtual StateBag ViewState
  296. {
  297. get
  298. {
  299. if(_viewState == null)
  300. _viewState = new StateBag (ViewStateIgnoresCase);
  301. if (IsTrackingViewState)
  302. _viewState.TrackViewState ();
  303. return _viewState;
  304. }
  305. }
  306. protected virtual bool ViewStateIgnoresCase
  307. {
  308. get {
  309. return false;
  310. }
  311. }
  312. internal bool AutoEventWireup {
  313. get { return autoEventWireup; }
  314. set { autoEventWireup = value; }
  315. }
  316. internal void SetBindingContainer (bool isBC)
  317. {
  318. bindingContainer = isBC;
  319. }
  320. internal void ResetChildNames ()
  321. {
  322. defaultNumberID = 0;
  323. }
  324. void NullifyUniqueID ()
  325. {
  326. uniqueID = null;
  327. if (_controls == null)
  328. return;
  329. foreach (Control c in _controls)
  330. c.NullifyUniqueID ();
  331. }
  332. protected internal virtual void AddedControl (Control control, int index)
  333. {
  334. /* Ensure the control don't have more than 1 parent */
  335. if (control._parent != null)
  336. control._parent.Controls.Remove (control);
  337. control._parent = this;
  338. control._page = Page;
  339. if (_isNamingContainer) {
  340. control._namingContainer = this;
  341. if (control.AutoID == true && control._userId == null) {
  342. control._userId = "_ictrl" + defaultNumberID++;
  343. }
  344. }
  345. if (inited)
  346. control.InitRecursive (_isNamingContainer ? this : null);
  347. if (loaded)
  348. control.LoadRecursive ();
  349. if (prerendered)
  350. control.PreRenderRecursiveInternal ();
  351. }
  352. protected virtual void AddParsedSubObject(object obj) //DIT
  353. {
  354. WebTrace.PushContext ("Control.AddParsedSubobject ()");
  355. Control c = obj as Control;
  356. WebTrace.WriteLine ("Start: {0} -> {1}", obj, (c != null) ? c.ID : String.Empty);
  357. if (c != null) Controls.Add(c);
  358. WebTrace.WriteLine ("End");
  359. WebTrace.PopContext ();
  360. }
  361. protected void BuildProfileTree(string parentId, bool calcViewState)
  362. {
  363. //TODO
  364. }
  365. protected void ClearChildViewState()
  366. {
  367. //TODO
  368. //Not quite sure about this. an example clears children then calls this, so I think
  369. //view state is local to the current object, not children.
  370. }
  371. protected virtual void CreateChildControls() {} //DIT
  372. protected virtual ControlCollection CreateControlCollection() //DIT
  373. {
  374. return new ControlCollection(this);
  375. }
  376. protected virtual void EnsureChildControls () //DIT
  377. {
  378. if (ChildControlsCreated == false && !creatingControls) {
  379. creatingControls = true;
  380. CreateChildControls();
  381. ChildControlsCreated = true;
  382. creatingControls = false;
  383. }
  384. }
  385. public virtual Control FindControl (string id)
  386. {
  387. return FindControl (id, 0);
  388. }
  389. Control LookForControlByName (string id)
  390. {
  391. if (!HasChildren)
  392. return null;
  393. foreach (Control c in _controls) {
  394. if (String.Compare (id, c._userId, true) == 0)
  395. return c;
  396. if (!c._isNamingContainer && c.HasChildren) {
  397. Control child = c.LookForControlByName (id);
  398. if (child != null)
  399. return child;
  400. }
  401. }
  402. return null;
  403. }
  404. protected virtual Control FindControl (string id, int pathOffset)
  405. {
  406. EnsureChildControls ();
  407. if (_controls == null)
  408. return null;
  409. Control namingContainer = null;
  410. if (!_isNamingContainer) {
  411. namingContainer = NamingContainer;
  412. if (namingContainer == null)
  413. return null;
  414. return namingContainer.FindControl (id, pathOffset);
  415. }
  416. int colon = id.IndexOf (':', pathOffset);
  417. if (colon == -1)
  418. return LookForControlByName (id.Substring (pathOffset));
  419. string idfound = id.Substring (pathOffset, colon - pathOffset);
  420. namingContainer = LookForControlByName (idfound);
  421. if (namingContainer == null || !namingContainer._isNamingContainer)
  422. return null;
  423. return namingContainer.FindControl (id, colon + 1);
  424. }
  425. protected virtual void LoadViewState(object savedState)
  426. {
  427. if (savedState != null)
  428. ViewState.LoadViewState (savedState);
  429. }
  430. [MonoTODO("Secure?")]
  431. protected string MapPathSecure(string virtualPath)
  432. {
  433. string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
  434. return Context.Request.MapPath (combined);
  435. }
  436. protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
  437. {
  438. return false;
  439. }
  440. protected virtual void OnDataBinding(EventArgs e) //DIT
  441. {
  442. if (_events != null)
  443. {
  444. EventHandler eh = (EventHandler)(_events[DataBindingEvent]);
  445. if (eh != null) eh(this, e);
  446. }
  447. }
  448. protected virtual void OnInit(EventArgs e) //DIT
  449. {
  450. if (_events != null)
  451. {
  452. EventHandler eh = (EventHandler)(_events[InitEvent]);
  453. if (eh != null) eh(this, e);
  454. }
  455. }
  456. protected virtual void OnLoad(EventArgs e) //DIT
  457. {
  458. if (_events != null)
  459. {
  460. EventHandler eh = (EventHandler)(_events[LoadEvent]);
  461. if (eh != null) eh(this, e);
  462. }
  463. }
  464. protected virtual void OnPreRender(EventArgs e) //DIT
  465. {
  466. if (_events != null)
  467. {
  468. EventHandler eh = (EventHandler)(_events[PreRenderEvent]);
  469. if (eh != null) eh(this, e);
  470. }
  471. }
  472. protected virtual void OnUnload(EventArgs e) //DIT
  473. {
  474. if (_events != null)
  475. {
  476. EventHandler eh = (EventHandler)(_events[UnloadEvent]);
  477. if (eh != null) eh(this, e);
  478. }
  479. }
  480. protected void RaiseBubbleEvent(object source, EventArgs args)
  481. {
  482. Control c = Parent;
  483. while (c != null) {
  484. if (c.OnBubbleEvent (source, args))
  485. break;
  486. c = c.Parent;
  487. }
  488. }
  489. protected virtual void Render(HtmlTextWriter writer) //DIT
  490. {
  491. RenderChildren(writer);
  492. }
  493. protected virtual void RenderChildren(HtmlTextWriter writer) //DIT
  494. {
  495. if (_renderMethodDelegate != null)
  496. _renderMethodDelegate(writer, this);
  497. else if (_controls != null)
  498. foreach (Control c in _controls)
  499. c.RenderControl(writer);
  500. }
  501. protected virtual object SaveViewState ()
  502. {
  503. if (_viewState == null)
  504. return null;
  505. return _viewState.SaveViewState ();
  506. }
  507. protected virtual void TrackViewState()
  508. {
  509. if (_viewState != null)
  510. _viewState.TrackViewState ();
  511. _trackViewState = true;
  512. }
  513. public virtual void Dispose()
  514. {
  515. if (_events != null)
  516. {
  517. EventHandler eh = (EventHandler) _events [DisposedEvent];
  518. if (eh != null)
  519. eh(this, EventArgs.Empty);
  520. }
  521. }
  522. public bool HasChildren
  523. {
  524. get { return (_controls != null && _controls.Count > 0); }
  525. }
  526. public event EventHandler DataBinding //DIT
  527. {
  528. add
  529. {
  530. Events.AddHandler(DataBindingEvent, value);
  531. }
  532. remove
  533. {
  534. Events.RemoveHandler(DataBindingEvent, value);
  535. }
  536. }
  537. public event EventHandler Disposed //DIT
  538. {
  539. add
  540. {
  541. Events.AddHandler(DisposedEvent, value);
  542. }
  543. remove
  544. {
  545. Events.RemoveHandler(DisposedEvent, value);
  546. }
  547. }
  548. public event EventHandler Init //DIT
  549. {
  550. add
  551. {
  552. Events.AddHandler(InitEvent, value);
  553. }
  554. remove
  555. {
  556. Events.RemoveHandler(InitEvent, value);
  557. }
  558. }
  559. public event EventHandler Load //DIT
  560. {
  561. add
  562. {
  563. Events.AddHandler(LoadEvent, value);
  564. }
  565. remove
  566. {
  567. Events.RemoveHandler(LoadEvent, value);
  568. }
  569. }
  570. public event EventHandler PreRender //DIT
  571. {
  572. add
  573. {
  574. Events.AddHandler(PreRenderEvent, value);
  575. }
  576. remove
  577. {
  578. Events.RemoveHandler(PreRenderEvent, value);
  579. }
  580. }
  581. public event EventHandler Unload //DIT
  582. {
  583. add
  584. {
  585. Events.AddHandler(UnloadEvent, value);
  586. }
  587. remove
  588. {
  589. Events.RemoveHandler(UnloadEvent, value);
  590. }
  591. }
  592. public virtual void DataBind() //DIT
  593. {
  594. OnDataBinding(EventArgs.Empty);
  595. if (_controls != null)
  596. foreach (Control c in _controls)
  597. c.DataBind();
  598. }
  599. public virtual bool HasControls() //DIT
  600. {
  601. if (_controls != null && _controls.Count >0) return true;
  602. return false;
  603. }
  604. public void RenderControl(HtmlTextWriter writer)
  605. {
  606. if (_visible)
  607. {
  608. //TODO: Something about tracing here.
  609. Render(writer);
  610. }
  611. }
  612. [MonoTODO]
  613. public string ResolveUrl(string relativeUrl)
  614. {
  615. return relativeUrl;
  616. }
  617. public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
  618. {
  619. WebTrace.PushContext ("Control.AddParsedSubobject ()");
  620. WebTrace.WriteLine ("Start");
  621. _renderMethodDelegate = renderMethod;
  622. WebTrace.WriteLine ("End");
  623. WebTrace.PopContext ();
  624. }
  625. protected void LoadRecursive()
  626. {
  627. OnLoad (EventArgs.Empty);
  628. if (_controls != null) {
  629. foreach (Control c in _controls)
  630. c.LoadRecursive ();
  631. }
  632. loaded = true;
  633. }
  634. protected void UnloadRecursive(Boolean dispose)
  635. {
  636. if (_controls != null) {
  637. foreach (Control c in _controls)
  638. c.UnloadRecursive (dispose);
  639. }
  640. OnUnload (EventArgs.Empty);
  641. if (dispose)
  642. Dispose();
  643. }
  644. protected void PreRenderRecursiveInternal()
  645. {
  646. if (_visible) {
  647. EnsureChildControls ();
  648. OnPreRender (EventArgs.Empty);
  649. if (_controls == null)
  650. return;
  651. foreach (Control c in _controls)
  652. c.PreRenderRecursiveInternal ();
  653. }
  654. prerendered = true;
  655. }
  656. protected void InitRecursive(Control namingContainer)
  657. {
  658. if (_controls != null) {
  659. if (_isNamingContainer)
  660. namingContainer = this;
  661. if (namingContainer != null &&
  662. namingContainer._userId == null &&
  663. namingContainer.autoID)
  664. namingContainer._userId = "_ictrl" + namingContainer.defaultNumberID++;
  665. foreach (Control c in _controls) {
  666. c._page = Page;
  667. c._namingContainer = namingContainer;
  668. c.InitRecursive (namingContainer);
  669. }
  670. }
  671. OnInit (EventArgs.Empty);
  672. TrackViewState ();
  673. inited = true;
  674. }
  675. internal object SaveViewStateRecursive ()
  676. {
  677. if (!EnableViewState)
  678. return null;
  679. ArrayList controlList = null;
  680. ArrayList controlStates = null;
  681. foreach (Control ctrl in Controls) {
  682. object ctrlState = ctrl.SaveViewStateRecursive ();
  683. if (ctrlState == null || ctrl.ID == null)
  684. continue;
  685. if (controlList == null) {
  686. controlList = new ArrayList ();
  687. controlStates = new ArrayList ();
  688. }
  689. controlList.Add (ctrl.ID);
  690. controlStates.Add (ctrlState);
  691. }
  692. object thisState = SaveViewState ();
  693. if (thisState == null && controlList == null && controlStates == null)
  694. return null;
  695. return new Triplet (thisState, controlList, controlStates);
  696. }
  697. internal void LoadViewStateRecursive (object savedState)
  698. {
  699. if (!EnableViewState || !Visible || savedState == null)
  700. return;
  701. Triplet savedInfo = (Triplet) savedState;
  702. LoadViewState (savedInfo.First);
  703. ArrayList controlList = savedInfo.Second as ArrayList;
  704. if (controlList == null)
  705. return;
  706. ArrayList controlStates = savedInfo.Third as ArrayList;
  707. int nControls = controlList.Count;
  708. for (int i = 0; i < nControls; i++) {
  709. Control c = FindControl ((string) controlList [i]);
  710. if (c != null && controlStates != null)
  711. c.LoadViewStateRecursive (controlStates [i]);
  712. }
  713. }
  714. void IParserAccessor.AddParsedSubObject(object obj)
  715. {
  716. AddParsedSubObject(obj);
  717. }
  718. DataBindingCollection IDataBindingsAccessor.DataBindings
  719. {
  720. get
  721. {
  722. if(dataBindings == null)
  723. dataBindings = new DataBindingCollection();
  724. return dataBindings;
  725. }
  726. }
  727. bool IDataBindingsAccessor.HasDataBindings
  728. {
  729. get
  730. {
  731. return (dataBindings!=null && dataBindings.Count>0);
  732. }
  733. }
  734. internal bool AutoID
  735. {
  736. get { return autoID; }
  737. set {
  738. if (value == false && !_isNamingContainer)
  739. return;
  740. autoID = value;
  741. }
  742. }
  743. internal void PreventAutoID()
  744. {
  745. AutoID = false;
  746. }
  747. protected internal virtual void RemovedControl (Control control)
  748. {
  749. control.UnloadRecursive (false);
  750. control._parent = null;
  751. control._page = null;
  752. control._namingContainer = null;
  753. }
  754. //TODO: I think there are some needed Interface implementations to do here.
  755. }
  756. }