Control.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  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. // Sanjay Gupta ([email protected])
  9. //
  10. // (C) Bob Smith
  11. // (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
  12. // (C) 2004 Novell, Inc. (http://www.novell.com)
  13. //
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. // This will provide extra information when trace is enabled. Might be too verbose.
  35. #define MONO_TRACE
  36. using System.Collections;
  37. using System.ComponentModel;
  38. using System.ComponentModel.Design;
  39. using System.ComponentModel.Design.Serialization;
  40. using System.Security.Permissions;
  41. using System.Web;
  42. using System.Web.Util;
  43. using System.Globalization;
  44. #if NET_2_0
  45. using System.Web.UI.Adapters;
  46. using System.IO;
  47. #endif
  48. namespace System.Web.UI
  49. {
  50. // CAS
  51. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  52. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  53. // attributes
  54. [DefaultProperty ("ID"), DesignerCategory ("Code"), ToolboxItemFilter ("System.Web.UI", ToolboxItemFilterType.Require)]
  55. [ToolboxItem ("System.Web.UI.Design.WebControlToolboxItem, " + Consts.AssemblySystem_Design)]
  56. [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  57. #if NET_2_0
  58. [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web,
  59. "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  60. [Bindable (true)]
  61. [Themeable (false)]
  62. #else
  63. [DesignerSerializer ("Microsoft.VSDesigner.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner,
  64. "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  65. #endif
  66. public partial class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
  67. #if NET_2_0
  68. , IUrlResolutionService, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
  69. #endif
  70. {
  71. static readonly object DataBindingEvent = new object ();
  72. static readonly object DisposedEvent = new object ();
  73. static readonly object InitEvent = new object ();
  74. static readonly object LoadEvent = new object ();
  75. static readonly object PreRenderEvent = new object ();
  76. static readonly object UnloadEvent = new object ();
  77. static string [] defaultNameArray;
  78. /* */
  79. int event_mask;
  80. const int databinding_mask = 1;
  81. const int disposed_mask = 1 << 1;
  82. const int init_mask = 1 << 2;
  83. const int load_mask = 1 << 3;
  84. const int prerender_mask = 1 << 4;
  85. const int unload_mask = 1 << 5;
  86. /* */
  87. string uniqueID;
  88. string _userId;
  89. ControlCollection _controls;
  90. Control _namingContainer;
  91. Page _page;
  92. Control _parent;
  93. ISite _site;
  94. HttpContext _context;
  95. StateBag _viewState;
  96. EventHandlerList _events;
  97. RenderMethod _renderMethodDelegate;
  98. Hashtable _controlsCache;
  99. int defaultNumberID;
  100. DataBindingCollection dataBindings;
  101. Hashtable pendingVS; // may hold unused viewstate data from child controls
  102. #if NET_2_0
  103. TemplateControl _templateControl;
  104. bool _isChildControlStateCleared;
  105. #endif
  106. string _templateSourceDirectory;
  107. /*************/
  108. int stateMask;
  109. const int ENABLE_VIEWSTATE = 1;
  110. const int VISIBLE = 1 << 1;
  111. const int AUTOID = 1 << 2;
  112. const int CREATING_CONTROLS = 1 << 3;
  113. const int BINDING_CONTAINER = 1 << 4;
  114. const int AUTO_EVENT_WIREUP = 1 << 5;
  115. const int IS_NAMING_CONTAINER = 1 << 6;
  116. const int VISIBLE_CHANGED = 1 << 7;
  117. const int TRACK_VIEWSTATE = 1 << 8;
  118. const int CHILD_CONTROLS_CREATED = 1 << 9;
  119. const int ID_SET = 1 << 10;
  120. const int INITED = 1 << 11;
  121. const int INITING = 1 << 12;
  122. const int VIEWSTATE_LOADED = 1 << 13;
  123. const int LOADED = 1 << 14;
  124. const int PRERENDERED = 1 << 15;
  125. #if NET_2_0
  126. const int ENABLE_THEMING = 1 << 16;
  127. #endif
  128. const int AUTOID_SET = 1 << 17;
  129. /*************/
  130. static Control () {
  131. defaultNameArray = new string [100];
  132. for (int i = 0; i < 100; i++)
  133. #if NET_2_0
  134. defaultNameArray [i] = String.Format ("ctl{0:D2}", i);
  135. #else
  136. defaultNameArray [i] = "_ctl" + i;
  137. #endif
  138. }
  139. public Control () {
  140. stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
  141. if (this is INamingContainer)
  142. stateMask |= IS_NAMING_CONTAINER;
  143. }
  144. #if NET_2_0
  145. [MonoTODO ("Not implemented, always returns null")]
  146. protected ControlAdapter Adapter {
  147. get {
  148. // for the time being, fool the
  149. // Control machinery into thinking we
  150. // don't have an Adapter. This will
  151. // allow us to write all the rest of
  152. // the Adapter handling code without
  153. // having to worry about *having*
  154. // adapters.
  155. return null;
  156. }
  157. }
  158. string _appRelativeTemplateSourceDirectory = null;
  159. [EditorBrowsable (EditorBrowsableState.Advanced)]
  160. [Browsable (false)]
  161. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  162. public string AppRelativeTemplateSourceDirectory {
  163. get {
  164. if (_appRelativeTemplateSourceDirectory != null)
  165. return _appRelativeTemplateSourceDirectory;
  166. string tempSrcDir = null;
  167. TemplateControl templateControl = TemplateControl;
  168. if (templateControl != null)
  169. if (!string.IsNullOrEmpty (templateControl.AppRelativeVirtualPath))
  170. tempSrcDir = VirtualPathUtility.GetDirectory (templateControl.AppRelativeVirtualPath, false);
  171. _appRelativeTemplateSourceDirectory = (tempSrcDir != null) ? tempSrcDir : "~/";
  172. return _appRelativeTemplateSourceDirectory;
  173. }
  174. [EditorBrowsable (EditorBrowsableState.Never)]
  175. set {
  176. _appRelativeTemplateSourceDirectory = value;
  177. _templateSourceDirectory = null;
  178. }
  179. }
  180. #endif
  181. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  182. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  183. public Control BindingContainer {
  184. get {
  185. Control container = NamingContainer;
  186. if (container != null && (container.stateMask & BINDING_CONTAINER) == 0)
  187. container = container.BindingContainer;
  188. return container;
  189. }
  190. }
  191. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  192. [Browsable (false)]
  193. [WebSysDescription ("An Identification of the control that is rendered.")]
  194. public virtual string ClientID {
  195. get {
  196. string client = UniqueID;
  197. if (client != null)
  198. #if NET_2_0
  199. client = UniqueID2ClientID (client);
  200. #else
  201. client = client.Replace (':', ClientIDSeparator);
  202. #endif
  203. stateMask |= ID_SET;
  204. return client;
  205. }
  206. }
  207. #if NET_2_0
  208. internal string UniqueID2ClientID (string uniqueId) {
  209. return uniqueId.Replace (IdSeparator, ClientIDSeparator);
  210. }
  211. protected char ClientIDSeparator
  212. #else
  213. char ClientIDSeparator
  214. #endif
  215. {
  216. get {
  217. return '_';
  218. }
  219. }
  220. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  221. [Browsable (false)]
  222. [WebSysDescription ("The child controls of this control.")]
  223. public virtual ControlCollection Controls //DIT
  224. {
  225. get {
  226. if (_controls == null)
  227. _controls = CreateControlCollection ();
  228. return _controls;
  229. }
  230. }
  231. #if NET_2_0
  232. [MonoTODO ("revisit once we have a real design strategy")]
  233. protected internal bool DesignMode {
  234. get { return false; }
  235. }
  236. #endif
  237. [DefaultValue (true), WebCategory ("Behavior")]
  238. [WebSysDescription ("An Identification of the control that is rendered.")]
  239. #if NET_2_0
  240. [Themeable (false)]
  241. #endif
  242. public virtual bool EnableViewState {
  243. get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
  244. set { SetMask (ENABLE_VIEWSTATE, value); }
  245. }
  246. [MergableProperty (false), ParenthesizePropertyName (true)]
  247. [WebSysDescription ("The name of the control that is rendered.")]
  248. #if NET_2_0
  249. [Filterable (false), Themeable (false)]
  250. #endif
  251. public virtual string ID {
  252. get {
  253. return (((stateMask & ID_SET) != 0) ? _userId : null);
  254. }
  255. set {
  256. if (value == "")
  257. value = null;
  258. stateMask |= ID_SET;
  259. _userId = value;
  260. NullifyUniqueID ();
  261. }
  262. }
  263. #if NET_2_0
  264. protected char IdSeparator {
  265. get {
  266. return '$';
  267. }
  268. }
  269. protected internal bool IsChildControlStateCleared {
  270. get { return _isChildControlStateCleared; }
  271. }
  272. protected internal bool IsViewStateEnabled {
  273. get {
  274. for (Control control = this; control != null; control = control.Parent)
  275. if (!control.EnableViewState)
  276. return false;
  277. return true;
  278. }
  279. }
  280. protected bool LoadViewStateByID {
  281. get {
  282. return false;
  283. }
  284. }
  285. #endif
  286. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  287. [Browsable (false)]
  288. [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
  289. public virtual Control NamingContainer {
  290. get {
  291. if (_namingContainer == null && _parent != null) {
  292. if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
  293. _namingContainer = _parent.NamingContainer;
  294. else
  295. _namingContainer = _parent;
  296. }
  297. return _namingContainer;
  298. }
  299. }
  300. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  301. [Browsable (false)]
  302. [WebSysDescription ("The webpage that this control resides on.")]
  303. #if NET_2_0
  304. [Bindable (false)]
  305. #endif
  306. public virtual Page Page //DIT
  307. {
  308. get {
  309. if (_page == null){
  310. if (NamingContainer != null)
  311. _page = NamingContainer.Page;
  312. else if (Parent != null)
  313. _page = Parent.Page;
  314. }
  315. return _page;
  316. }
  317. set {
  318. _page = value;
  319. }
  320. }
  321. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  322. [Browsable (false)]
  323. [WebSysDescription ("The parent control of this control.")]
  324. public virtual Control Parent //DIT
  325. {
  326. get {
  327. return _parent;
  328. }
  329. }
  330. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  331. [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
  332. [WebSysDescription ("The site this control is part of.")]
  333. public ISite Site //DIT
  334. {
  335. get {
  336. return _site;
  337. }
  338. set {
  339. _site = value;
  340. }
  341. }
  342. #if NET_2_0
  343. [Browsable (false)]
  344. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  345. public TemplateControl TemplateControl {
  346. get {
  347. return TemplateControlInternal;
  348. }
  349. [EditorBrowsable (EditorBrowsableState.Never)]
  350. set { _templateControl = value; }
  351. }
  352. internal virtual TemplateControl TemplateControlInternal {
  353. get {
  354. if (_templateControl != null)
  355. return _templateControl;
  356. if (_parent != null)
  357. return _parent.TemplateControl;
  358. return null;
  359. }
  360. }
  361. #endif
  362. #if !TARGET_J2EE
  363. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  364. [Browsable (false)]
  365. [WebSysDescription ("A virtual directory containing the parent of the control.")]
  366. public virtual string TemplateSourceDirectory {
  367. get {
  368. #if NET_2_0
  369. if (_templateSourceDirectory == null) {
  370. TemplateControl tc = TemplateControl;
  371. if (tc == null) {
  372. HttpContext ctx = Context;
  373. if (ctx != null)
  374. _templateSourceDirectory = VirtualPathUtility.GetDirectory (ctx.Request.CurrentExecutionFilePath);
  375. }
  376. else if (tc != this)
  377. _templateSourceDirectory = tc.TemplateSourceDirectory;
  378. if (_templateSourceDirectory == null && this is TemplateControl) {
  379. string path = ((TemplateControl) this).AppRelativeVirtualPath;
  380. if (path != null) {
  381. // Pretend our application virtual root is "/" even if it isn't - we just
  382. // want to get an absolute url out of relative one, without the real
  383. // application root prepended to it.
  384. string ret = VirtualPathUtility.GetDirectory (VirtualPathUtility.ToAbsolute (path, "/"));
  385. int len = ret.Length;
  386. if (len <= 1)
  387. return ret;
  388. if (ret [--len] == '/')
  389. _templateSourceDirectory = ret.Substring (0, len);
  390. }
  391. else
  392. _templateSourceDirectory = String.Empty;
  393. }
  394. if (_templateSourceDirectory == null)
  395. _templateSourceDirectory = String.Empty;
  396. }
  397. return _templateSourceDirectory;
  398. #else
  399. if (_templateSourceDirectory == null) {
  400. HttpContext ctx = HttpContext.Current;
  401. HttpRequest req = ctx != null ? ctx.Request : null;
  402. _templateSourceDirectory = (_parent == null)
  403. ? req != null ? VirtualPathUtility.RemoveTrailingSlash (
  404. VirtualPathUtility.GetDirectory (
  405. HttpContext.Current.Request.CurrentExecutionFilePath)) : String.Empty
  406. : _parent.TemplateSourceDirectory;
  407. }
  408. return _templateSourceDirectory;
  409. #endif
  410. }
  411. }
  412. #endif
  413. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  414. [Browsable (false)]
  415. [WebSysDescription ("The unique ID of the control.")]
  416. public virtual string UniqueID {
  417. get {
  418. if (uniqueID != null)
  419. return uniqueID;
  420. if (NamingContainer == null)
  421. return _userId;
  422. EnsureIDInternal ();
  423. string prefix = NamingContainer.UniqueID;
  424. #if TARGET_J2EE
  425. // For J2EE portlets we need to add the namespace to the ID.
  426. if (NamingContainer == Page && Page.PortletNamespace != null)
  427. prefix = Page.PortletNamespace;
  428. else
  429. #endif
  430. if (NamingContainer == Page || prefix == null) {
  431. uniqueID = _userId;
  432. return uniqueID;
  433. }
  434. #if NET_2_0
  435. uniqueID = prefix + IdSeparator + _userId;
  436. #else
  437. uniqueID = prefix + ":" + _userId;
  438. #endif
  439. return uniqueID;
  440. }
  441. }
  442. void SetMask (int m, bool val) {
  443. if (val)
  444. stateMask |= m;
  445. else
  446. stateMask &= ~m;
  447. }
  448. [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
  449. [WebSysDescription ("Visiblity state of the control.")]
  450. public virtual bool Visible {
  451. get {
  452. if ((stateMask & VISIBLE) == 0)
  453. return false;
  454. if (_parent != null)
  455. return _parent.Visible;
  456. return true;
  457. }
  458. set {
  459. if ((value && (stateMask & VISIBLE) == 0) ||
  460. (!value && (stateMask & VISIBLE) != 0)) {
  461. if (IsTrackingViewState)
  462. stateMask |= VISIBLE_CHANGED;
  463. }
  464. SetMask (VISIBLE, value);
  465. }
  466. }
  467. protected bool ChildControlsCreated {
  468. get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
  469. set {
  470. if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0) {
  471. if (_controls != null)
  472. _controls.Clear ();
  473. }
  474. SetMask (CHILD_CONTROLS_CREATED, value);
  475. }
  476. }
  477. [Browsable (false)]
  478. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  479. protected virtual HttpContext Context //DIT
  480. {
  481. get {
  482. HttpContext context;
  483. if (_context != null)
  484. return _context;
  485. if (_parent == null)
  486. return HttpContext.Current;
  487. context = _parent.Context;
  488. if (context != null)
  489. return context;
  490. return HttpContext.Current;
  491. }
  492. }
  493. protected EventHandlerList Events {
  494. get {
  495. if (_events == null)
  496. _events = new EventHandlerList ();
  497. return _events;
  498. }
  499. }
  500. protected bool HasChildViewState {
  501. get {
  502. return (pendingVS != null && pendingVS.Count > 0);
  503. }
  504. }
  505. protected bool IsTrackingViewState {
  506. get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
  507. }
  508. [Browsable (false)]
  509. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  510. [WebSysDescription ("ViewState")]
  511. protected virtual StateBag ViewState {
  512. get {
  513. if (_viewState == null)
  514. _viewState = new StateBag (ViewStateIgnoresCase);
  515. if (IsTrackingViewState)
  516. _viewState.TrackViewState ();
  517. return _viewState;
  518. }
  519. }
  520. [Browsable (false)]
  521. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  522. protected virtual bool ViewStateIgnoresCase {
  523. get {
  524. return false;
  525. }
  526. }
  527. internal bool AutoEventWireup {
  528. get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
  529. set { SetMask (AUTO_EVENT_WIREUP, value); }
  530. }
  531. internal void SetBindingContainer (bool isBC) {
  532. SetMask (BINDING_CONTAINER, isBC);
  533. }
  534. internal void ResetChildNames () {
  535. defaultNumberID = 0;
  536. }
  537. string GetDefaultName () {
  538. string defaultName;
  539. if (defaultNumberID > 99) {
  540. #if NET_2_0
  541. defaultName = "ctl" + defaultNumberID++;
  542. #else
  543. defaultName = "_ctl" + defaultNumberID++;
  544. #endif
  545. }
  546. else {
  547. defaultName = defaultNameArray [defaultNumberID++];
  548. }
  549. return defaultName;
  550. }
  551. void NullifyUniqueID () {
  552. uniqueID = null;
  553. if (!HasControls ())
  554. return;
  555. for (int i = 0; i < _controls.Count; i++)
  556. _controls [i].NullifyUniqueID ();
  557. }
  558. protected internal virtual void AddedControl (Control control, int index) {
  559. ResetControlsCache ();
  560. /* Ensure the control don't have more than 1 parent */
  561. if (control._parent != null)
  562. control._parent.Controls.Remove (control);
  563. control._parent = this;
  564. Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
  565. if ((stateMask & (INITING | INITED)) != 0)
  566. control.InitRecursive (nc);
  567. else {
  568. control.SetNamingContainer (nc);
  569. return;
  570. }
  571. if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
  572. if (pendingVS != null) {
  573. object vs = pendingVS [index];
  574. if (vs != null) {
  575. pendingVS.Remove (index);
  576. if (pendingVS.Count == 0)
  577. pendingVS = null;
  578. control.LoadViewStateRecursive (vs);
  579. }
  580. }
  581. }
  582. if ((stateMask & LOADED) != 0)
  583. control.LoadRecursive ();
  584. if ((stateMask & PRERENDERED) != 0)
  585. control.PreRenderRecursiveInternal ();
  586. }
  587. void SetNamingContainer (Control nc) {
  588. if (nc != null) {
  589. _namingContainer = nc;
  590. if (AutoID)
  591. EnsureIDInternal ();
  592. }
  593. }
  594. protected virtual void AddParsedSubObject (object obj) //DIT
  595. {
  596. Control c = obj as Control;
  597. if (c != null)
  598. Controls.Add (c);
  599. }
  600. #if NET_2_0
  601. [EditorBrowsable (EditorBrowsableState.Advanced)]
  602. public virtual void ApplyStyleSheetSkin (Page page) {
  603. if (!EnableTheming) /* this enough? */
  604. return;
  605. /* apply the style sheet skin here */
  606. if (page.StyleSheetPageTheme != null) {
  607. ControlSkin cs = page.StyleSheetPageTheme.GetControlSkin (GetType (), SkinID);
  608. if (cs != null)
  609. cs.ApplySkin (this);
  610. }
  611. }
  612. #endif
  613. protected void BuildProfileTree (string parentId, bool calcViewState) {
  614. //TODO
  615. }
  616. #if NET_2_0
  617. protected void ClearChildControlState () {
  618. _isChildControlStateCleared = true;
  619. }
  620. protected void ClearChildState () {
  621. ClearChildViewState ();
  622. ClearChildControlState ();
  623. }
  624. #endif
  625. protected void ClearChildViewState () {
  626. pendingVS = null;
  627. }
  628. #if NET_2_0
  629. protected internal
  630. #else
  631. protected
  632. #endif
  633. virtual void CreateChildControls () { } //DIT
  634. protected virtual ControlCollection CreateControlCollection () //DIT
  635. {
  636. return new ControlCollection (this);
  637. }
  638. protected virtual void EnsureChildControls () {
  639. if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
  640. stateMask |= CREATING_CONTROLS;
  641. #if NET_2_0
  642. if (Adapter != null)
  643. Adapter.CreateChildControls ();
  644. else
  645. #endif
  646. CreateChildControls ();
  647. ChildControlsCreated = true;
  648. stateMask &= ~CREATING_CONTROLS;
  649. }
  650. }
  651. void EnsureIDInternal () {
  652. if (_userId != null)
  653. return;
  654. _userId = NamingContainer.GetDefaultName ();
  655. SetMask (AUTOID_SET, true);
  656. }
  657. #if NET_2_0
  658. protected void EnsureID () {
  659. if (NamingContainer == null)
  660. return;
  661. EnsureIDInternal ();
  662. SetMask (ID_SET, true);
  663. }
  664. protected bool HasEvents () {
  665. return _events != null;
  666. }
  667. #endif
  668. void ResetControlsCache ()
  669. {
  670. _controlsCache = null;
  671. if ((this.stateMask & IS_NAMING_CONTAINER) == 0 && Parent != null)
  672. Parent.ResetControlsCache ();
  673. }
  674. Hashtable InitControlsCache ()
  675. {
  676. if (_controlsCache != null)
  677. return _controlsCache;
  678. if ((this.stateMask & IS_NAMING_CONTAINER) != 0 || Parent == null)
  679. //LAMESPEC: MS' docs don't mention it, but FindControl is case insensitive.
  680. #if NET_2_0
  681. _controlsCache = new Hashtable (StringComparer.OrdinalIgnoreCase);
  682. #else
  683. _controlsCache = new Hashtable (CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
  684. #endif
  685. else
  686. _controlsCache = Parent.InitControlsCache ();
  687. return _controlsCache;
  688. }
  689. void EnsureControlsCache ()
  690. {
  691. if (_controlsCache != null)
  692. return;
  693. InitControlsCache ();
  694. FillControlCache (this);
  695. }
  696. void FillControlCache (Control control)
  697. {
  698. if (!HasControls ())
  699. return;
  700. foreach (Control c in control._controls) {
  701. try {
  702. if (c._userId != null)
  703. _controlsCache.Add (c._userId, c);
  704. }
  705. catch (Exception ex) {
  706. throw new HttpException ("Found more than one control with ID '" + c._userId + "'", ex);
  707. }
  708. if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ())
  709. FillControlCache (c);
  710. }
  711. }
  712. protected bool IsLiteralContent () {
  713. if (HasControls () && _controls.Count == 1 && (_controls [0] is LiteralControl))
  714. return true;
  715. return false;
  716. }
  717. [WebSysDescription ("")]
  718. public virtual Control FindControl (string id) {
  719. return FindControl (id, 0);
  720. }
  721. Control LookForControlByName (string id) {
  722. #if TARGET_J2EE
  723. if (this == Page && id != null && id == Page.PortletNamespace)
  724. return this;
  725. #endif
  726. EnsureControlsCache ();
  727. return (Control) _controlsCache [id];
  728. }
  729. protected virtual Control FindControl (string id, int pathOffset) {
  730. EnsureChildControls ();
  731. Control namingContainer = null;
  732. if ((stateMask & IS_NAMING_CONTAINER) == 0) {
  733. namingContainer = NamingContainer;
  734. if (namingContainer == null)
  735. return null;
  736. return namingContainer.FindControl (id, pathOffset);
  737. }
  738. if (!HasControls ())
  739. return null;
  740. #if NET_2_0
  741. int separatorIdx = id.IndexOf (IdSeparator, pathOffset);
  742. #else
  743. int separatorIdx = id.IndexOf (':', pathOffset);
  744. #endif
  745. if (separatorIdx == -1)
  746. return LookForControlByName (id.Substring (pathOffset));
  747. string idfound = id.Substring (pathOffset, separatorIdx - pathOffset);
  748. namingContainer = LookForControlByName (idfound);
  749. if (namingContainer == null)
  750. return null;
  751. return namingContainer.FindControl (id, separatorIdx + 1);
  752. }
  753. protected virtual void LoadViewState (object savedState) {
  754. if (savedState != null) {
  755. ViewState.LoadViewState (savedState);
  756. object o = ViewState ["Visible"];
  757. if (o != null) {
  758. SetMask (VISIBLE, (bool) o);
  759. stateMask |= VISIBLE_CHANGED;
  760. }
  761. }
  762. }
  763. // [MonoTODO("Secure?")]
  764. protected string MapPathSecure (string virtualPath) {
  765. string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
  766. return Context.Request.MapPath (combined);
  767. }
  768. protected virtual bool OnBubbleEvent (object source, EventArgs args) //DIT
  769. {
  770. #if MONO_TRACE
  771. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  772. string type_name = null;
  773. if (trace != null) {
  774. type_name = GetType ().Name;
  775. trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
  776. }
  777. #endif
  778. return false;
  779. }
  780. protected virtual void OnDataBinding (EventArgs e) {
  781. if ((event_mask & databinding_mask) != 0) {
  782. EventHandler eh = (EventHandler) (_events [DataBindingEvent]);
  783. if (eh != null) {
  784. #if MONO_TRACE
  785. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  786. string type_name = null;
  787. if (trace != null) {
  788. type_name = GetType ().Name;
  789. trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
  790. }
  791. #endif
  792. eh (this, e);
  793. }
  794. }
  795. }
  796. #if NET_2_0
  797. protected internal
  798. #else
  799. protected
  800. #endif
  801. virtual void OnInit (EventArgs e) {
  802. if ((event_mask & init_mask) != 0) {
  803. EventHandler eh = (EventHandler) (_events [InitEvent]);
  804. if (eh != null) {
  805. #if MONO_TRACE
  806. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  807. string type_name = null;
  808. if (trace != null) {
  809. type_name = GetType ().Name;
  810. trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
  811. }
  812. #endif
  813. eh (this, e);
  814. }
  815. }
  816. }
  817. #if NET_2_0
  818. protected internal
  819. #else
  820. protected
  821. #endif
  822. virtual void OnLoad (EventArgs e) {
  823. if ((event_mask & load_mask) != 0) {
  824. EventHandler eh = (EventHandler) (_events [LoadEvent]);
  825. if (eh != null) {
  826. #if MONO_TRACE
  827. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  828. string type_name = null;
  829. if (trace != null) {
  830. type_name = GetType ().Name;
  831. trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
  832. }
  833. #endif
  834. eh (this, e);
  835. }
  836. }
  837. }
  838. #if NET_2_0
  839. protected internal
  840. #else
  841. protected
  842. #endif
  843. virtual void OnPreRender (EventArgs e) {
  844. if ((event_mask & prerender_mask) != 0) {
  845. EventHandler eh = (EventHandler) (_events [PreRenderEvent]);
  846. if (eh != null) {
  847. #if MONO_TRACE
  848. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  849. string type_name = null;
  850. if (trace != null) {
  851. type_name = GetType ().Name;
  852. trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
  853. }
  854. #endif
  855. eh (this, e);
  856. }
  857. }
  858. }
  859. #if NET_2_0
  860. protected internal
  861. #else
  862. protected
  863. #endif
  864. virtual void OnUnload (EventArgs e) {
  865. if ((event_mask & unload_mask) != 0) {
  866. EventHandler eh = (EventHandler) (_events [UnloadEvent]);
  867. if (eh != null) {
  868. #if MONO_TRACE
  869. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  870. string type_name = null;
  871. if (trace != null) {
  872. type_name = GetType ().Name;
  873. trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
  874. }
  875. #endif
  876. eh (this, e);
  877. }
  878. }
  879. }
  880. #if NET_2_0
  881. protected internal Stream OpenFile (string path) {
  882. try {
  883. string filePath = Context.Server.MapPath (path);
  884. return File.OpenRead (filePath);
  885. }
  886. catch (UnauthorizedAccessException) {
  887. throw new HttpException ("Access to the specified file was denied.");
  888. }
  889. }
  890. internal string GetPhysicalFilePath (string virtualPath) {
  891. Page page = Page;
  892. if (VirtualPathUtility.IsAbsolute (virtualPath))
  893. return page != null ? page.MapPath (virtualPath) : Context.Server.MapPath (virtualPath);
  894. // We need to determine whether one of our parents is a
  895. // master page. If so, we need to map the path
  896. // relatively to the master page and not our containing
  897. // page/control. This is necessary for cases when a
  898. // relative path is used in a control placed in a master
  899. // page and the master page is referenced from a
  900. // location other than its own. In such cases MS.NET looks
  901. // for the file in the directory where the master page
  902. // is.
  903. //
  904. // An example of where it is needed is at
  905. //
  906. // http://quickstarts.asp.net/QuickStartv20/aspnet/samples/masterpages/masterpages_cs/pages/default.aspx
  907. //
  908. MasterPage master = null;
  909. Control ctrl = Parent;
  910. while (ctrl != null) {
  911. if (ctrl is MasterPage) {
  912. master = ctrl as MasterPage;
  913. break;
  914. }
  915. ctrl = ctrl.Parent;
  916. }
  917. string path;
  918. if (master != null)
  919. path = VirtualPathUtility.Combine (master.TemplateSourceDirectory, virtualPath);
  920. else
  921. path = VirtualPathUtility.Combine (TemplateSourceDirectory, virtualPath);
  922. return page != null ? page.MapPath (path) : Context.Server.MapPath (path);
  923. }
  924. #endif
  925. protected void RaiseBubbleEvent (object source, EventArgs args) {
  926. Control c = Parent;
  927. while (c != null) {
  928. #if MONO_TRACE
  929. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  930. string type_name = null;
  931. if (trace != null) {
  932. type_name = GetType ().Name;
  933. trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
  934. }
  935. #endif
  936. if (c.OnBubbleEvent (source, args)) {
  937. #if MONO_TRACE
  938. if (trace != null)
  939. trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
  940. #endif
  941. break;
  942. }
  943. #if MONO_TRACE
  944. if (trace != null)
  945. trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
  946. #endif
  947. c = c.Parent;
  948. }
  949. }
  950. #if NET_2_0
  951. protected internal
  952. #else
  953. protected
  954. #endif
  955. virtual void Render (HtmlTextWriter writer) //DIT
  956. {
  957. RenderChildren (writer);
  958. }
  959. #if NET_2_0
  960. protected internal
  961. #else
  962. protected
  963. #endif
  964. virtual void RenderChildren (HtmlTextWriter writer) //DIT
  965. {
  966. if (_renderMethodDelegate != null) {
  967. _renderMethodDelegate (writer, this);
  968. }
  969. else if (_controls != null) {
  970. int len = _controls.Count;
  971. Control c;
  972. for (int i = 0; i < len; i++) {
  973. c = _controls [i];
  974. if (c == null)
  975. continue;
  976. #if NET_2_0
  977. if (c.Adapter != null)
  978. c.RenderControl (writer, c.Adapter);
  979. else
  980. #endif
  981. c.RenderControl (writer);
  982. }
  983. }
  984. }
  985. #if NET_2_0
  986. protected virtual ControlAdapter ResolveAdapter () {
  987. throw new NotImplementedException ();
  988. }
  989. #endif
  990. protected virtual object SaveViewState () {
  991. if ((stateMask & VISIBLE_CHANGED) != 0) {
  992. ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
  993. }
  994. else if (_viewState == null) {
  995. return null;
  996. }
  997. return _viewState.SaveViewState ();
  998. }
  999. protected virtual void TrackViewState () {
  1000. if (_viewState != null)
  1001. _viewState.TrackViewState ();
  1002. stateMask |= TRACK_VIEWSTATE;
  1003. }
  1004. public virtual void Dispose () {
  1005. if ((event_mask & disposed_mask) != 0) {
  1006. EventHandler eh = (EventHandler) (_events [DisposedEvent]);
  1007. if (eh != null)
  1008. eh (this, EventArgs.Empty);
  1009. }
  1010. }
  1011. [WebCategory ("FIXME")]
  1012. [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
  1013. public event EventHandler DataBinding {
  1014. add {
  1015. event_mask |= databinding_mask;
  1016. Events.AddHandler (DataBindingEvent, value);
  1017. }
  1018. remove { Events.RemoveHandler (DataBindingEvent, value); }
  1019. }
  1020. [WebSysDescription ("Raised when the contol is disposed.")]
  1021. public event EventHandler Disposed {
  1022. add {
  1023. event_mask |= disposed_mask;
  1024. Events.AddHandler (DisposedEvent, value);
  1025. }
  1026. remove { Events.RemoveHandler (DisposedEvent, value); }
  1027. }
  1028. [WebSysDescription ("Raised when the page containing the control is initialized.")]
  1029. public event EventHandler Init {
  1030. add {
  1031. event_mask |= init_mask;
  1032. Events.AddHandler (InitEvent, value);
  1033. }
  1034. remove { Events.RemoveHandler (InitEvent, value); }
  1035. }
  1036. [WebSysDescription ("Raised after the page containing the control has been loaded.")]
  1037. public event EventHandler Load {
  1038. add {
  1039. event_mask |= load_mask;
  1040. Events.AddHandler (LoadEvent, value);
  1041. }
  1042. remove { Events.RemoveHandler (LoadEvent, value); }
  1043. }
  1044. [WebSysDescription ("Raised before the page containing the control is rendered.")]
  1045. public event EventHandler PreRender {
  1046. add {
  1047. event_mask |= prerender_mask;
  1048. Events.AddHandler (PreRenderEvent, value);
  1049. }
  1050. remove { Events.RemoveHandler (PreRenderEvent, value); }
  1051. }
  1052. [WebSysDescription ("Raised when the page containing the control is unloaded.")]
  1053. public event EventHandler Unload {
  1054. add {
  1055. event_mask |= unload_mask;
  1056. Events.AddHandler (UnloadEvent, value);
  1057. }
  1058. remove { Events.RemoveHandler (UnloadEvent, value); }
  1059. }
  1060. public virtual void DataBind () //DIT
  1061. {
  1062. #if NET_2_0
  1063. DataBind (true);
  1064. #else
  1065. OnDataBinding (EventArgs.Empty);
  1066. DataBindChildren();
  1067. #endif
  1068. }
  1069. #if NET_2_0
  1070. protected virtual
  1071. #endif
  1072. void DataBindChildren () {
  1073. if (!HasControls ())
  1074. return;
  1075. int len = _controls.Count;
  1076. for (int i = 0; i < len; i++) {
  1077. Control c = _controls [i];
  1078. c.DataBind ();
  1079. }
  1080. }
  1081. public virtual bool HasControls () {
  1082. return (_controls != null && _controls.Count > 0);
  1083. }
  1084. #if NET_2_0
  1085. public virtual
  1086. #else
  1087. public
  1088. #endif
  1089. void RenderControl (HtmlTextWriter writer) {
  1090. if ((stateMask & VISIBLE) != 0) {
  1091. HttpContext ctx = Context;
  1092. TraceContext trace = (ctx != null) ? ctx.Trace : null;
  1093. int pos = 0;
  1094. if ((trace != null) && trace.IsEnabled)
  1095. pos = ctx.Response.GetOutputByteCount ();
  1096. Render (writer);
  1097. if ((trace != null) && trace.IsEnabled) {
  1098. int size = ctx.Response.GetOutputByteCount () - pos;
  1099. trace.SaveSize (this, size >= 0 ? size : 0);
  1100. }
  1101. }
  1102. }
  1103. #if NET_2_0
  1104. protected void RenderControl (HtmlTextWriter writer,
  1105. ControlAdapter adapter) {
  1106. if ((stateMask & VISIBLE) != 0) {
  1107. adapter.BeginRender (writer);
  1108. adapter.Render (writer);
  1109. adapter.EndRender (writer);
  1110. }
  1111. }
  1112. #endif
  1113. public string ResolveUrl (string relativeUrl) {
  1114. if (relativeUrl == null)
  1115. throw new ArgumentNullException ("relativeUrl");
  1116. if (relativeUrl == "")
  1117. return "";
  1118. if (relativeUrl [0] == '#')
  1119. return relativeUrl;
  1120. string ts = TemplateSourceDirectory;
  1121. if (ts == null || ts.Length == 0 ||
  1122. Context == null || Context.Response == null ||
  1123. !UrlUtils.IsRelativeUrl (relativeUrl))
  1124. return relativeUrl;
  1125. HttpResponse resp = Context.Response;
  1126. return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
  1127. }
  1128. #if NET_2_0
  1129. public
  1130. #else
  1131. internal
  1132. #endif
  1133. string ResolveClientUrl (string relativeUrl) {
  1134. #if TARGET_J2EE
  1135. // There are no relative paths when rendering a J2EE portlet
  1136. if (Page != null && Page.PortletNamespace != null)
  1137. return ResolveUrl (relativeUrl);
  1138. #endif
  1139. if (relativeUrl == null)
  1140. throw new ArgumentNullException ("relativeUrl");
  1141. if (relativeUrl.Length == 0)
  1142. return String.Empty;
  1143. if (VirtualPathUtility.IsAbsolute (relativeUrl) || relativeUrl.IndexOf (':') >= 0)
  1144. return relativeUrl;
  1145. HttpContext context = Context;
  1146. if (context != null && context.Request != null) {
  1147. string templateSourceDirectory = TemplateSourceDirectory;
  1148. if (templateSourceDirectory == null || templateSourceDirectory.Length == 0)
  1149. return relativeUrl;
  1150. string basePath = context.Request.CurrentExecutionFilePath;
  1151. if (basePath.Length > 1 && basePath [basePath.Length - 1] != '/')
  1152. basePath = VirtualPathUtility.GetDirectory (basePath, false);
  1153. if (VirtualPathUtility.IsAppRelative (relativeUrl))
  1154. return VirtualPathUtility.MakeRelative (basePath, relativeUrl);
  1155. string templatePath = VirtualPathUtility.AppendTrailingSlash (templateSourceDirectory);
  1156. if (basePath.Length == templatePath.Length && String.CompareOrdinal (basePath, templatePath) == 0)
  1157. return relativeUrl;
  1158. relativeUrl = VirtualPathUtility.Combine (templatePath, relativeUrl);
  1159. return VirtualPathUtility.MakeRelative (basePath, relativeUrl);
  1160. }
  1161. return relativeUrl;
  1162. }
  1163. internal bool HasRenderMethodDelegate () {
  1164. return _renderMethodDelegate != null;
  1165. }
  1166. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1167. public void SetRenderMethodDelegate (RenderMethod renderMethod) //DIT
  1168. {
  1169. _renderMethodDelegate = renderMethod;
  1170. }
  1171. internal void LoadRecursive () {
  1172. #if MONO_TRACE
  1173. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1174. string type_name = null;
  1175. if (trace != null) {
  1176. type_name = GetType ().Name;
  1177. trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
  1178. }
  1179. #endif
  1180. #if NET_2_0
  1181. if (Adapter != null)
  1182. Adapter.OnLoad (EventArgs.Empty);
  1183. else
  1184. #endif
  1185. OnLoad (EventArgs.Empty);
  1186. if (HasControls ()) {
  1187. int len = _controls.Count;
  1188. for (int i = 0; i < len; i++) {
  1189. Control c = _controls [i];
  1190. c.LoadRecursive ();
  1191. }
  1192. }
  1193. #if MONO_TRACE
  1194. if (trace != null)
  1195. trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
  1196. #endif
  1197. stateMask |= LOADED;
  1198. }
  1199. internal void UnloadRecursive (Boolean dispose) {
  1200. #if MONO_TRACE
  1201. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1202. string type_name = null;
  1203. if (trace != null) {
  1204. type_name = GetType ().Name;
  1205. trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
  1206. }
  1207. #endif
  1208. if (HasControls ()) {
  1209. int len = _controls.Count;
  1210. for (int i = 0; i < len; i++) {
  1211. Control c = _controls [i];
  1212. c.UnloadRecursive (dispose);
  1213. }
  1214. }
  1215. #if MONO_TRACE
  1216. if (trace != null)
  1217. trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
  1218. #endif
  1219. #if NET_2_0
  1220. if (Adapter != null)
  1221. Adapter.OnUnload (EventArgs.Empty);
  1222. else
  1223. #endif
  1224. OnUnload (EventArgs.Empty);
  1225. if (dispose)
  1226. Dispose ();
  1227. }
  1228. internal void PreRenderRecursiveInternal () {
  1229. if ((stateMask & VISIBLE) != 0) {
  1230. EnsureChildControls ();
  1231. #if MONO_TRACE
  1232. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1233. string type_name = null;
  1234. if (trace != null) {
  1235. type_name = GetType ().Name;
  1236. trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
  1237. }
  1238. #endif
  1239. #if NET_2_0
  1240. if (Adapter != null)
  1241. Adapter.OnPreRender (EventArgs.Empty);
  1242. else
  1243. #endif
  1244. OnPreRender (EventArgs.Empty);
  1245. if (!HasControls ())
  1246. return;
  1247. int len = _controls.Count;
  1248. for (int i = 0; i < len; i++) {
  1249. Control c = _controls [i];
  1250. c.PreRenderRecursiveInternal ();
  1251. }
  1252. #if MONO_TRACE
  1253. if (trace != null)
  1254. trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
  1255. #endif
  1256. }
  1257. stateMask |= PRERENDERED;
  1258. }
  1259. internal void InitRecursive (Control namingContainer) {
  1260. #if MONO_TRACE
  1261. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1262. string type_name = null;
  1263. if (trace != null) {
  1264. type_name = GetType ().Name;
  1265. trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
  1266. }
  1267. #endif
  1268. SetNamingContainer (namingContainer);
  1269. if (HasControls ()) {
  1270. if ((stateMask & IS_NAMING_CONTAINER) != 0)
  1271. namingContainer = this;
  1272. int len = _controls.Count;
  1273. for (int i = 0; i < len; i++) {
  1274. Control c = _controls [i];
  1275. c.InitRecursive (namingContainer);
  1276. }
  1277. }
  1278. stateMask |= INITING;
  1279. #if NET_2_0
  1280. ApplyTheme ();
  1281. if (Adapter != null)
  1282. Adapter.OnInit (EventArgs.Empty);
  1283. else
  1284. #endif
  1285. OnInit (EventArgs.Empty);
  1286. #if MONO_TRACE
  1287. if (trace != null)
  1288. trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
  1289. #endif
  1290. TrackViewState ();
  1291. stateMask |= INITED;
  1292. stateMask &= ~INITING;
  1293. }
  1294. internal object SaveViewStateRecursive () {
  1295. if (!EnableViewState)
  1296. return null;
  1297. #if MONO_TRACE
  1298. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1299. string type_name = null;
  1300. if (trace != null) {
  1301. type_name = GetType ().Name;
  1302. trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
  1303. }
  1304. #endif
  1305. ArrayList controlList = null;
  1306. ArrayList controlStates = null;
  1307. int idx = -1;
  1308. if (HasControls ()) {
  1309. int len = _controls.Count;
  1310. for (int i = 0; i < len; i++) {
  1311. Control ctrl = _controls [i];
  1312. object ctrlState = ctrl.SaveViewStateRecursive ();
  1313. idx++;
  1314. if (ctrlState == null)
  1315. continue;
  1316. if (controlList == null) {
  1317. controlList = new ArrayList ();
  1318. controlStates = new ArrayList ();
  1319. }
  1320. controlList.Add (idx);
  1321. controlStates.Add (ctrlState);
  1322. }
  1323. }
  1324. object thisState = SaveViewState ();
  1325. if (thisState == null && controlList == null && controlStates == null) {
  1326. #if MONO_TRACE
  1327. if (trace != null) {
  1328. trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
  1329. trace.SaveViewState (this, null);
  1330. }
  1331. #endif
  1332. return null;
  1333. }
  1334. #if MONO_TRACE
  1335. if (trace != null) {
  1336. trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
  1337. trace.SaveViewState (this, thisState);
  1338. }
  1339. #endif
  1340. return new Triplet (thisState, controlList, controlStates);
  1341. }
  1342. internal void LoadViewStateRecursive (object savedState) {
  1343. if (!EnableViewState || savedState == null)
  1344. return;
  1345. #if MONO_TRACE
  1346. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1347. string type_name = null;
  1348. if (trace != null) {
  1349. type_name = GetType ().Name;
  1350. trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
  1351. }
  1352. #endif
  1353. Triplet savedInfo = (Triplet) savedState;
  1354. LoadViewState (savedInfo.First);
  1355. ArrayList controlList = savedInfo.Second as ArrayList;
  1356. if (controlList == null)
  1357. return;
  1358. ArrayList controlStates = savedInfo.Third as ArrayList;
  1359. int nControls = controlList.Count;
  1360. for (int i = 0; i < nControls; i++) {
  1361. int k = (int) controlList [i];
  1362. if (k < Controls.Count && controlStates != null) {
  1363. Control c = Controls [k];
  1364. c.LoadViewStateRecursive (controlStates [i]);
  1365. }
  1366. else {
  1367. if (pendingVS == null)
  1368. pendingVS = new Hashtable ();
  1369. pendingVS [k] = controlStates [i];
  1370. }
  1371. }
  1372. #if MONO_TRACE
  1373. if (trace != null)
  1374. trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
  1375. #endif
  1376. stateMask |= VIEWSTATE_LOADED;
  1377. }
  1378. #if NET_2_0
  1379. internal ControlSkin controlSkin;
  1380. internal void ApplyTheme () {
  1381. #if MONO_TRACE
  1382. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1383. string type_name = null;
  1384. if (trace != null) {
  1385. type_name = GetType ().Name;
  1386. trace.Write ("control", String.Format ("ApplyThemeRecursive {0} {1}", _userId, type_name));
  1387. }
  1388. #endif
  1389. if (Page.PageTheme != null && EnableTheming) {
  1390. ControlSkin controlSkin = Page.PageTheme.GetControlSkin (GetType (), SkinID);
  1391. if (controlSkin != null)
  1392. controlSkin.ApplySkin (this);
  1393. }
  1394. #if MONO_TRACE
  1395. if (trace != null)
  1396. trace.Write ("control", String.Format ("End ApplyThemeRecursive {0} {1}", _userId, type_name));
  1397. #endif
  1398. }
  1399. #endif
  1400. internal bool AutoID {
  1401. get { return (stateMask & AUTOID) != 0; }
  1402. set {
  1403. if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
  1404. return;
  1405. SetMask (AUTOID, value);
  1406. }
  1407. }
  1408. protected internal virtual void RemovedControl (Control control) {
  1409. control.UnloadRecursive (false);
  1410. control._parent = null;
  1411. control._page = null;
  1412. control._namingContainer = null;
  1413. if ((control.stateMask & AUTOID_SET) != 0) {
  1414. control._userId = null;
  1415. control.SetMask (ID_SET, false);
  1416. }
  1417. control.NullifyUniqueID ();
  1418. }
  1419. #if NET_2_0
  1420. string skinId = string.Empty;
  1421. bool _enableTheming = true;
  1422. [Browsable (false)]
  1423. [Themeable (false)]
  1424. [DefaultValue (true)]
  1425. public virtual bool EnableTheming {
  1426. get {
  1427. if ((stateMask & ENABLE_THEMING) != 0)
  1428. return _enableTheming;
  1429. if (_parent != null)
  1430. return _parent.EnableTheming;
  1431. return true;
  1432. }
  1433. set {
  1434. SetMask (ENABLE_THEMING, true);
  1435. _enableTheming = value;
  1436. }
  1437. }
  1438. [Browsable (false)]
  1439. [DefaultValue ("")]
  1440. [Filterable (false)]
  1441. public virtual string SkinID {
  1442. get { return skinId; }
  1443. set { skinId = value; }
  1444. }
  1445. ControlBuilder IControlBuilderAccessor.ControlBuilder {
  1446. get { throw new NotImplementedException (); }
  1447. }
  1448. IDictionary IControlDesignerAccessor.GetDesignModeState () {
  1449. throw new NotImplementedException ();
  1450. }
  1451. void IControlDesignerAccessor.SetDesignModeState (IDictionary designData) {
  1452. SetDesignModeState (designData);
  1453. }
  1454. void IControlDesignerAccessor.SetOwnerControl (Control control) {
  1455. throw new NotImplementedException ();
  1456. }
  1457. IDictionary IControlDesignerAccessor.UserData {
  1458. get { throw new NotImplementedException (); }
  1459. }
  1460. ExpressionBindingCollection expressionBindings;
  1461. ExpressionBindingCollection IExpressionsAccessor.Expressions {
  1462. get {
  1463. if (expressionBindings == null)
  1464. expressionBindings = new ExpressionBindingCollection ();
  1465. return expressionBindings;
  1466. }
  1467. }
  1468. bool IExpressionsAccessor.HasExpressions {
  1469. get {
  1470. return (expressionBindings != null && expressionBindings.Count > 0);
  1471. }
  1472. }
  1473. public virtual void Focus () {
  1474. Page.SetFocus (this);
  1475. }
  1476. protected internal virtual void LoadControlState (object state) {
  1477. }
  1478. protected internal virtual object SaveControlState () {
  1479. return null;
  1480. }
  1481. protected virtual void DataBind (bool raiseOnDataBinding) {
  1482. bool foundDataItem = false;
  1483. if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
  1484. object o = DataBinder.GetDataItem (this, out foundDataItem);
  1485. if (foundDataItem)
  1486. Page.PushDataItemContext (o);
  1487. }
  1488. try {
  1489. if (raiseOnDataBinding)
  1490. OnDataBinding (EventArgs.Empty);
  1491. DataBindChildren ();
  1492. }
  1493. finally {
  1494. if (foundDataItem)
  1495. Page.PopDataItemContext ();
  1496. }
  1497. }
  1498. protected virtual IDictionary GetDesignModeState () {
  1499. throw new NotImplementedException ();
  1500. }
  1501. protected virtual void SetDesignModeState (IDictionary data) {
  1502. throw new NotImplementedException ();
  1503. }
  1504. #endif
  1505. void IParserAccessor.AddParsedSubObject (object obj) {
  1506. this.AddParsedSubObject (obj);
  1507. }
  1508. DataBindingCollection IDataBindingsAccessor.DataBindings {
  1509. get {
  1510. if (dataBindings == null) {
  1511. dataBindings = new DataBindingCollection ();
  1512. }
  1513. return dataBindings;
  1514. }
  1515. }
  1516. bool IDataBindingsAccessor.HasDataBindings {
  1517. get {
  1518. if (dataBindings != null && dataBindings.Count > 0) {
  1519. return true;
  1520. }
  1521. return false;
  1522. }
  1523. }
  1524. }
  1525. }