2
0

Control.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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. //TODO
  366. //Not quite sure about this. an example clears children then calls this, so I think
  367. //view state is local to the current object, not children.
  368. }
  369. protected virtual void CreateChildControls() {} //DIT
  370. protected virtual ControlCollection CreateControlCollection() //DIT
  371. {
  372. return new ControlCollection(this);
  373. }
  374. protected virtual void EnsureChildControls () //DIT
  375. {
  376. if (ChildControlsCreated == false && !creatingControls) {
  377. creatingControls = true;
  378. CreateChildControls();
  379. ChildControlsCreated = true;
  380. creatingControls = false;
  381. }
  382. }
  383. protected bool IsLiteralContent()
  384. {
  385. if (_controls != null)
  386. if (_controls.Count == 1)
  387. if (_controls[0] is LiteralControl)
  388. return true;
  389. return false;
  390. }
  391. public virtual Control FindControl (string id)
  392. {
  393. return FindControl (id, 0);
  394. }
  395. Control LookForControlByName (string id)
  396. {
  397. if (!HasChildren)
  398. return null;
  399. foreach (Control c in _controls) {
  400. if (String.Compare (id, c._userId, true) == 0)
  401. return c;
  402. if (!c._isNamingContainer && c.HasChildren) {
  403. Control child = c.LookForControlByName (id);
  404. if (child != null)
  405. return child;
  406. }
  407. }
  408. return null;
  409. }
  410. protected virtual Control FindControl (string id, int pathOffset)
  411. {
  412. EnsureChildControls ();
  413. if (_controls == null)
  414. return null;
  415. Control namingContainer = null;
  416. if (!_isNamingContainer) {
  417. namingContainer = NamingContainer;
  418. if (namingContainer == null)
  419. return null;
  420. return namingContainer.FindControl (id, pathOffset);
  421. }
  422. int colon = id.IndexOf (':', pathOffset);
  423. if (colon == -1)
  424. return LookForControlByName (id.Substring (pathOffset));
  425. string idfound = id.Substring (pathOffset, colon - pathOffset);
  426. namingContainer = LookForControlByName (idfound);
  427. if (namingContainer == null)
  428. return null;
  429. return namingContainer.FindControl (id, colon + 1);
  430. }
  431. protected virtual void LoadViewState(object savedState)
  432. {
  433. if (savedState != null) {
  434. ViewState.LoadViewState (savedState);
  435. object o = ViewState ["Visible"];
  436. if (o != null)
  437. _visible = (bool) o;
  438. }
  439. }
  440. [MonoTODO("Secure?")]
  441. protected string MapPathSecure(string virtualPath)
  442. {
  443. string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
  444. return Context.Request.MapPath (combined);
  445. }
  446. protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
  447. {
  448. return false;
  449. }
  450. protected virtual void OnDataBinding(EventArgs e) //DIT
  451. {
  452. if (_events != null)
  453. {
  454. EventHandler eh = (EventHandler)(_events[DataBindingEvent]);
  455. if (eh != null) eh(this, e);
  456. }
  457. }
  458. protected virtual void OnInit(EventArgs e) //DIT
  459. {
  460. if (_events != null)
  461. {
  462. EventHandler eh = (EventHandler)(_events[InitEvent]);
  463. if (eh != null) eh(this, e);
  464. }
  465. }
  466. protected virtual void OnLoad(EventArgs e) //DIT
  467. {
  468. if (_events != null)
  469. {
  470. EventHandler eh = (EventHandler)(_events[LoadEvent]);
  471. if (eh != null) eh(this, e);
  472. }
  473. }
  474. protected virtual void OnPreRender(EventArgs e) //DIT
  475. {
  476. if (_events != null)
  477. {
  478. EventHandler eh = (EventHandler)(_events[PreRenderEvent]);
  479. if (eh != null) eh(this, e);
  480. }
  481. }
  482. protected virtual void OnUnload(EventArgs e) //DIT
  483. {
  484. if (_events != null)
  485. {
  486. EventHandler eh = (EventHandler)(_events[UnloadEvent]);
  487. if (eh != null) eh(this, e);
  488. }
  489. }
  490. protected void RaiseBubbleEvent(object source, EventArgs args)
  491. {
  492. Control c = Parent;
  493. while (c != null) {
  494. if (c.OnBubbleEvent (source, args))
  495. break;
  496. c = c.Parent;
  497. }
  498. }
  499. protected virtual void Render(HtmlTextWriter writer) //DIT
  500. {
  501. RenderChildren(writer);
  502. }
  503. protected virtual void RenderChildren(HtmlTextWriter writer) //DIT
  504. {
  505. if (_renderMethodDelegate != null)
  506. _renderMethodDelegate(writer, this);
  507. else if (_controls != null)
  508. foreach (Control c in _controls)
  509. c.RenderControl(writer);
  510. }
  511. protected virtual object SaveViewState ()
  512. {
  513. if (_viewState == null)
  514. return null;
  515. return _viewState.SaveViewState ();
  516. }
  517. protected virtual void TrackViewState()
  518. {
  519. if (_viewState != null)
  520. _viewState.TrackViewState ();
  521. _trackViewState = true;
  522. }
  523. public virtual void Dispose()
  524. {
  525. if (_events != null)
  526. {
  527. EventHandler eh = (EventHandler) _events [DisposedEvent];
  528. if (eh != null)
  529. eh(this, EventArgs.Empty);
  530. }
  531. }
  532. internal bool HasChildren
  533. {
  534. get { return (_controls != null && _controls.Count > 0); }
  535. }
  536. [WebCategory ("FIXME")]
  537. [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
  538. public event EventHandler DataBinding //DIT
  539. {
  540. add
  541. {
  542. Events.AddHandler(DataBindingEvent, value);
  543. }
  544. remove
  545. {
  546. Events.RemoveHandler(DataBindingEvent, value);
  547. }
  548. }
  549. [WebSysDescription ("Raised when the contol is disposed.")]
  550. public event EventHandler Disposed //DIT
  551. {
  552. add
  553. {
  554. Events.AddHandler(DisposedEvent, value);
  555. }
  556. remove
  557. {
  558. Events.RemoveHandler(DisposedEvent, value);
  559. }
  560. }
  561. [WebSysDescription ("Raised when the page containing the control is initialized.")]
  562. public event EventHandler Init //DIT
  563. {
  564. add
  565. {
  566. Events.AddHandler(InitEvent, value);
  567. }
  568. remove
  569. {
  570. Events.RemoveHandler(InitEvent, value);
  571. }
  572. }
  573. [WebSysDescription ("Raised after the page containing the control has been loaded.")]
  574. public event EventHandler Load //DIT
  575. {
  576. add
  577. {
  578. Events.AddHandler(LoadEvent, value);
  579. }
  580. remove
  581. {
  582. Events.RemoveHandler(LoadEvent, value);
  583. }
  584. }
  585. [WebSysDescription ("Raised before the page containing the control is rendered.")]
  586. public event EventHandler PreRender //DIT
  587. {
  588. add
  589. {
  590. Events.AddHandler(PreRenderEvent, value);
  591. }
  592. remove
  593. {
  594. Events.RemoveHandler(PreRenderEvent, value);
  595. }
  596. }
  597. [WebSysDescription ("Raised when the page containing the control is unloaded.")]
  598. public event EventHandler Unload //DIT
  599. {
  600. add
  601. {
  602. Events.AddHandler(UnloadEvent, value);
  603. }
  604. remove
  605. {
  606. Events.RemoveHandler(UnloadEvent, value);
  607. }
  608. }
  609. public virtual void DataBind() //DIT
  610. {
  611. OnDataBinding(EventArgs.Empty);
  612. if (_controls != null)
  613. foreach (Control c in _controls)
  614. c.DataBind();
  615. }
  616. public virtual bool HasControls() //DIT
  617. {
  618. if (_controls != null && _controls.Count >0) return true;
  619. return false;
  620. }
  621. public void RenderControl(HtmlTextWriter writer)
  622. {
  623. if (_visible)
  624. {
  625. //TODO: Something about tracing here.
  626. Render(writer);
  627. }
  628. }
  629. public string ResolveUrl(string relativeUrl)
  630. {
  631. if (relativeUrl == null)
  632. throw new ArgumentNullException ("relativeUrl");
  633. if (relativeUrl == "")
  634. return "";
  635. string ts = TemplateSourceDirectory;
  636. if (UrlUtils.IsRelativeUrl (relativeUrl) == false || ts == "")
  637. return relativeUrl;
  638. HttpResponse resp = Context.Response;
  639. return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
  640. }
  641. [EditorBrowsable (EditorBrowsableState.Advanced)]
  642. public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
  643. {
  644. WebTrace.PushContext ("Control.AddParsedSubobject ()");
  645. WebTrace.WriteLine ("Start");
  646. _renderMethodDelegate = renderMethod;
  647. WebTrace.WriteLine ("End");
  648. WebTrace.PopContext ();
  649. }
  650. internal void LoadRecursive()
  651. {
  652. OnLoad (EventArgs.Empty);
  653. if (_controls != null) {
  654. foreach (Control c in _controls)
  655. c.LoadRecursive ();
  656. }
  657. loaded = true;
  658. }
  659. internal void UnloadRecursive(Boolean dispose)
  660. {
  661. if (_controls != null) {
  662. foreach (Control c in _controls)
  663. c.UnloadRecursive (dispose);
  664. }
  665. OnUnload (EventArgs.Empty);
  666. if (dispose)
  667. Dispose();
  668. }
  669. internal void PreRenderRecursiveInternal()
  670. {
  671. if (_visible) {
  672. EnsureChildControls ();
  673. OnPreRender (EventArgs.Empty);
  674. if (_controls == null)
  675. return;
  676. foreach (Control c in _controls)
  677. c.PreRenderRecursiveInternal ();
  678. }
  679. prerendered = true;
  680. }
  681. internal void InitRecursive(Control namingContainer)
  682. {
  683. if (_controls != null) {
  684. if (_isNamingContainer)
  685. namingContainer = this;
  686. if (namingContainer != null &&
  687. namingContainer._userId == null &&
  688. namingContainer.autoID)
  689. namingContainer._userId = namingContainer.GetDefaultName () + "b";
  690. foreach (Control c in _controls) {
  691. c._page = Page;
  692. c._namingContainer = namingContainer;
  693. if (namingContainer != null && c._userId == null && c.autoID)
  694. c._userId = namingContainer.GetDefaultName () + "c";
  695. c.InitRecursive (namingContainer);
  696. }
  697. }
  698. OnInit (EventArgs.Empty);
  699. TrackViewState ();
  700. inited = true;
  701. }
  702. internal object SaveViewStateRecursive ()
  703. {
  704. if (!EnableViewState)
  705. return null;
  706. ArrayList controlList = null;
  707. ArrayList controlStates = null;
  708. int idx = -1;
  709. foreach (Control ctrl in Controls) {
  710. object ctrlState = ctrl.SaveViewStateRecursive ();
  711. idx++;
  712. if (ctrlState == null)
  713. continue;
  714. if (controlList == null) {
  715. controlList = new ArrayList ();
  716. controlStates = new ArrayList ();
  717. }
  718. controlList.Add (idx);
  719. controlStates.Add (ctrlState);
  720. }
  721. object thisState = SaveViewState ();
  722. if (thisState == null && controlList == null && controlStates == null)
  723. return null;
  724. return new Triplet (thisState, controlList, controlStates);
  725. }
  726. internal void LoadViewStateRecursive (object savedState)
  727. {
  728. if (!EnableViewState || !Visible || savedState == null)
  729. return;
  730. Triplet savedInfo = (Triplet) savedState;
  731. LoadViewState (savedInfo.First);
  732. ArrayList controlList = savedInfo.Second as ArrayList;
  733. if (controlList == null)
  734. return;
  735. ArrayList controlStates = savedInfo.Third as ArrayList;
  736. int nControls = controlList.Count;
  737. for (int i = 0; i < nControls; i++) {
  738. int k = (int) controlList [i];
  739. if (k < Controls.Count && controlStates != null) {
  740. Control c = Controls [k];
  741. c.LoadViewStateRecursive (controlStates [i]);
  742. } else {
  743. if (pendingVS == null)
  744. pendingVS = new Hashtable ();
  745. pendingVS [k] = controlStates [i];
  746. }
  747. }
  748. viewStateLoaded = true;
  749. }
  750. void IParserAccessor.AddParsedSubObject(object obj)
  751. {
  752. AddParsedSubObject(obj);
  753. }
  754. DataBindingCollection IDataBindingsAccessor.DataBindings
  755. {
  756. get
  757. {
  758. if(dataBindings == null)
  759. dataBindings = new DataBindingCollection();
  760. return dataBindings;
  761. }
  762. }
  763. bool IDataBindingsAccessor.HasDataBindings
  764. {
  765. get
  766. {
  767. return (dataBindings!=null && dataBindings.Count>0);
  768. }
  769. }
  770. internal bool AutoID
  771. {
  772. get { return autoID; }
  773. set {
  774. if (value == false && _isNamingContainer)
  775. return;
  776. autoID = value;
  777. }
  778. }
  779. internal void PreventAutoID()
  780. {
  781. AutoID = false;
  782. }
  783. protected internal virtual void RemovedControl (Control control)
  784. {
  785. control.UnloadRecursive (false);
  786. control._parent = null;
  787. control._page = null;
  788. control._namingContainer = null;
  789. }
  790. //TODO: I think there are some needed Interface implementations to do here.
  791. }
  792. }