Control.cs 45 KB

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