2
0

Control.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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 = _namingContainer.GetDefaultName ();
  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. string GetDefaultName ()
  325. {
  326. return "_ctrl" + defaultNumberID++;
  327. }
  328. void NullifyUniqueID ()
  329. {
  330. uniqueID = null;
  331. if (_controls == null)
  332. return;
  333. foreach (Control c in _controls)
  334. c.NullifyUniqueID ();
  335. }
  336. protected internal virtual void AddedControl (Control control, int index)
  337. {
  338. /* Ensure the control don't have more than 1 parent */
  339. if (control._parent != null)
  340. control._parent.Controls.Remove (control);
  341. control._parent = this;
  342. control._page = _page;
  343. Control nc = _isNamingContainer ? this : NamingContainer;
  344. if (nc != null) {
  345. control._namingContainer = nc;
  346. if (control.AutoID == true && control._userId == null)
  347. control._userId = nc.GetDefaultName () + "a";
  348. }
  349. if (inited)
  350. control.InitRecursive (nc);
  351. if (loaded)
  352. control.LoadRecursive ();
  353. if (prerendered)
  354. control.PreRenderRecursiveInternal ();
  355. }
  356. protected virtual void AddParsedSubObject(object obj) //DIT
  357. {
  358. WebTrace.PushContext ("Control.AddParsedSubobject ()");
  359. Control c = obj as Control;
  360. WebTrace.WriteLine ("Start: {0} -> {1}", obj, (c != null) ? c.ID : String.Empty);
  361. if (c != null) Controls.Add(c);
  362. WebTrace.WriteLine ("End");
  363. WebTrace.PopContext ();
  364. }
  365. protected void BuildProfileTree(string parentId, bool calcViewState)
  366. {
  367. //TODO
  368. }
  369. protected void ClearChildViewState()
  370. {
  371. //TODO
  372. //Not quite sure about this. an example clears children then calls this, so I think
  373. //view state is local to the current object, not children.
  374. }
  375. protected virtual void CreateChildControls() {} //DIT
  376. protected virtual ControlCollection CreateControlCollection() //DIT
  377. {
  378. return new ControlCollection(this);
  379. }
  380. protected virtual void EnsureChildControls () //DIT
  381. {
  382. if (ChildControlsCreated == false && !creatingControls) {
  383. creatingControls = true;
  384. CreateChildControls();
  385. ChildControlsCreated = true;
  386. creatingControls = false;
  387. }
  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. }
  434. [MonoTODO("Secure?")]
  435. protected string MapPathSecure(string virtualPath)
  436. {
  437. string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
  438. return Context.Request.MapPath (combined);
  439. }
  440. protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
  441. {
  442. return false;
  443. }
  444. protected virtual void OnDataBinding(EventArgs e) //DIT
  445. {
  446. if (_events != null)
  447. {
  448. EventHandler eh = (EventHandler)(_events[DataBindingEvent]);
  449. if (eh != null) eh(this, e);
  450. }
  451. }
  452. protected virtual void OnInit(EventArgs e) //DIT
  453. {
  454. if (_events != null)
  455. {
  456. EventHandler eh = (EventHandler)(_events[InitEvent]);
  457. if (eh != null) eh(this, e);
  458. }
  459. }
  460. protected virtual void OnLoad(EventArgs e) //DIT
  461. {
  462. if (_events != null)
  463. {
  464. EventHandler eh = (EventHandler)(_events[LoadEvent]);
  465. if (eh != null) eh(this, e);
  466. }
  467. }
  468. protected virtual void OnPreRender(EventArgs e) //DIT
  469. {
  470. if (_events != null)
  471. {
  472. EventHandler eh = (EventHandler)(_events[PreRenderEvent]);
  473. if (eh != null) eh(this, e);
  474. }
  475. }
  476. protected virtual void OnUnload(EventArgs e) //DIT
  477. {
  478. if (_events != null)
  479. {
  480. EventHandler eh = (EventHandler)(_events[UnloadEvent]);
  481. if (eh != null) eh(this, e);
  482. }
  483. }
  484. protected void RaiseBubbleEvent(object source, EventArgs args)
  485. {
  486. Control c = Parent;
  487. while (c != null) {
  488. if (c.OnBubbleEvent (source, args))
  489. break;
  490. c = c.Parent;
  491. }
  492. }
  493. protected virtual void Render(HtmlTextWriter writer) //DIT
  494. {
  495. RenderChildren(writer);
  496. }
  497. protected virtual void RenderChildren(HtmlTextWriter writer) //DIT
  498. {
  499. if (_renderMethodDelegate != null)
  500. _renderMethodDelegate(writer, this);
  501. else if (_controls != null)
  502. foreach (Control c in _controls)
  503. c.RenderControl(writer);
  504. }
  505. protected virtual object SaveViewState ()
  506. {
  507. if (_viewState == null)
  508. return null;
  509. return _viewState.SaveViewState ();
  510. }
  511. protected virtual void TrackViewState()
  512. {
  513. if (_viewState != null)
  514. _viewState.TrackViewState ();
  515. _trackViewState = true;
  516. }
  517. public virtual void Dispose()
  518. {
  519. if (_events != null)
  520. {
  521. EventHandler eh = (EventHandler) _events [DisposedEvent];
  522. if (eh != null)
  523. eh(this, EventArgs.Empty);
  524. }
  525. }
  526. public bool HasChildren
  527. {
  528. get { return (_controls != null && _controls.Count > 0); }
  529. }
  530. public event EventHandler DataBinding //DIT
  531. {
  532. add
  533. {
  534. Events.AddHandler(DataBindingEvent, value);
  535. }
  536. remove
  537. {
  538. Events.RemoveHandler(DataBindingEvent, value);
  539. }
  540. }
  541. public event EventHandler Disposed //DIT
  542. {
  543. add
  544. {
  545. Events.AddHandler(DisposedEvent, value);
  546. }
  547. remove
  548. {
  549. Events.RemoveHandler(DisposedEvent, value);
  550. }
  551. }
  552. public event EventHandler Init //DIT
  553. {
  554. add
  555. {
  556. Events.AddHandler(InitEvent, value);
  557. }
  558. remove
  559. {
  560. Events.RemoveHandler(InitEvent, value);
  561. }
  562. }
  563. public event EventHandler Load //DIT
  564. {
  565. add
  566. {
  567. Events.AddHandler(LoadEvent, value);
  568. }
  569. remove
  570. {
  571. Events.RemoveHandler(LoadEvent, value);
  572. }
  573. }
  574. public event EventHandler PreRender //DIT
  575. {
  576. add
  577. {
  578. Events.AddHandler(PreRenderEvent, value);
  579. }
  580. remove
  581. {
  582. Events.RemoveHandler(PreRenderEvent, value);
  583. }
  584. }
  585. public event EventHandler Unload //DIT
  586. {
  587. add
  588. {
  589. Events.AddHandler(UnloadEvent, value);
  590. }
  591. remove
  592. {
  593. Events.RemoveHandler(UnloadEvent, value);
  594. }
  595. }
  596. public virtual void DataBind() //DIT
  597. {
  598. OnDataBinding(EventArgs.Empty);
  599. if (_controls != null)
  600. foreach (Control c in _controls)
  601. c.DataBind();
  602. }
  603. public virtual bool HasControls() //DIT
  604. {
  605. if (_controls != null && _controls.Count >0) return true;
  606. return false;
  607. }
  608. public void RenderControl(HtmlTextWriter writer)
  609. {
  610. if (_visible)
  611. {
  612. //TODO: Something about tracing here.
  613. Render(writer);
  614. }
  615. }
  616. public string ResolveUrl(string relativeUrl)
  617. {
  618. if (relativeUrl == null)
  619. throw new ArgumentNullException ("relativeUrl");
  620. if (relativeUrl == "")
  621. return "";
  622. string ts = TemplateSourceDirectory;
  623. if (UrlUtils.IsRelativeUrl (relativeUrl) == false || ts == "")
  624. return relativeUrl;
  625. HttpResponse resp = Context.Response;
  626. return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
  627. }
  628. public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
  629. {
  630. WebTrace.PushContext ("Control.AddParsedSubobject ()");
  631. WebTrace.WriteLine ("Start");
  632. _renderMethodDelegate = renderMethod;
  633. WebTrace.WriteLine ("End");
  634. WebTrace.PopContext ();
  635. }
  636. protected void LoadRecursive()
  637. {
  638. OnLoad (EventArgs.Empty);
  639. if (_controls != null) {
  640. foreach (Control c in _controls)
  641. c.LoadRecursive ();
  642. }
  643. loaded = true;
  644. }
  645. protected void UnloadRecursive(Boolean dispose)
  646. {
  647. if (_controls != null) {
  648. foreach (Control c in _controls)
  649. c.UnloadRecursive (dispose);
  650. }
  651. OnUnload (EventArgs.Empty);
  652. if (dispose)
  653. Dispose();
  654. }
  655. protected void PreRenderRecursiveInternal()
  656. {
  657. if (_visible) {
  658. EnsureChildControls ();
  659. OnPreRender (EventArgs.Empty);
  660. if (_controls == null)
  661. return;
  662. foreach (Control c in _controls)
  663. c.PreRenderRecursiveInternal ();
  664. }
  665. prerendered = true;
  666. }
  667. protected void InitRecursive(Control namingContainer)
  668. {
  669. if (_controls != null) {
  670. if (_isNamingContainer)
  671. namingContainer = this;
  672. if (namingContainer != null &&
  673. namingContainer._userId == null &&
  674. namingContainer.autoID)
  675. namingContainer._userId = namingContainer.GetDefaultName () + "b";
  676. foreach (Control c in _controls) {
  677. c._page = Page;
  678. c._namingContainer = namingContainer;
  679. if (namingContainer != null && c._userId == null && c.autoID)
  680. c._userId = namingContainer.GetDefaultName () + "c";
  681. c.InitRecursive (namingContainer);
  682. }
  683. }
  684. OnInit (EventArgs.Empty);
  685. TrackViewState ();
  686. inited = true;
  687. }
  688. internal object SaveViewStateRecursive ()
  689. {
  690. if (!EnableViewState)
  691. return null;
  692. ArrayList controlList = null;
  693. ArrayList controlStates = null;
  694. foreach (Control ctrl in Controls) {
  695. object ctrlState = ctrl.SaveViewStateRecursive ();
  696. if (ctrlState == null || ctrl.ID == null)
  697. continue;
  698. if (controlList == null) {
  699. controlList = new ArrayList ();
  700. controlStates = new ArrayList ();
  701. }
  702. controlList.Add (ctrl.ID);
  703. controlStates.Add (ctrlState);
  704. }
  705. object thisState = SaveViewState ();
  706. if (thisState == null && controlList == null && controlStates == null)
  707. return null;
  708. return new Triplet (thisState, controlList, controlStates);
  709. }
  710. internal void LoadViewStateRecursive (object savedState)
  711. {
  712. if (!EnableViewState || !Visible || savedState == null)
  713. return;
  714. Triplet savedInfo = (Triplet) savedState;
  715. LoadViewState (savedInfo.First);
  716. ArrayList controlList = savedInfo.Second as ArrayList;
  717. if (controlList == null)
  718. return;
  719. ArrayList controlStates = savedInfo.Third as ArrayList;
  720. int nControls = controlList.Count;
  721. for (int i = 0; i < nControls; i++) {
  722. Control c = FindControl ((string) controlList [i]);
  723. if (c != null && controlStates != null)
  724. c.LoadViewStateRecursive (controlStates [i]);
  725. }
  726. }
  727. void IParserAccessor.AddParsedSubObject(object obj)
  728. {
  729. AddParsedSubObject(obj);
  730. }
  731. DataBindingCollection IDataBindingsAccessor.DataBindings
  732. {
  733. get
  734. {
  735. if(dataBindings == null)
  736. dataBindings = new DataBindingCollection();
  737. return dataBindings;
  738. }
  739. }
  740. bool IDataBindingsAccessor.HasDataBindings
  741. {
  742. get
  743. {
  744. return (dataBindings!=null && dataBindings.Count>0);
  745. }
  746. }
  747. internal bool AutoID
  748. {
  749. get { return autoID; }
  750. set {
  751. if (value == false && _isNamingContainer)
  752. return;
  753. autoID = value;
  754. }
  755. }
  756. internal void PreventAutoID()
  757. {
  758. AutoID = false;
  759. }
  760. protected internal virtual void RemovedControl (Control control)
  761. {
  762. control.UnloadRecursive (false);
  763. control._parent = null;
  764. control._page = null;
  765. control._namingContainer = null;
  766. }
  767. //TODO: I think there are some needed Interface implementations to do here.
  768. }
  769. }