Control.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142
  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. // Marek Habersack <[email protected]>
  10. //
  11. // (C) Bob Smith
  12. // (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
  13. // (C) 2004-2010 Novell, Inc. (http://www.novell.com)
  14. //
  15. //
  16. // Permission is hereby granted, free of charge, to any person obtaining
  17. // a copy of this software and associated documentation files (the
  18. // "Software"), to deal in the Software without restriction, including
  19. // without limitation the rights to use, copy, modify, merge, publish,
  20. // distribute, sublicense, and/or sell copies of the Software, and to
  21. // permit persons to whom the Software is furnished to do so, subject to
  22. // the following conditions:
  23. //
  24. // The above copyright notice and this permission notice shall be
  25. // included in all copies or substantial portions of the Software.
  26. //
  27. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  31. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  32. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  33. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  34. //
  35. using System.Collections;
  36. using System.Collections.Generic;
  37. using System.ComponentModel;
  38. using System.ComponentModel.Design;
  39. using System.ComponentModel.Design.Serialization;
  40. using System.Globalization;
  41. using System.IO;
  42. using System.Security.Permissions;
  43. using System.Text;
  44. using System.Web;
  45. using System.Web.Configuration;
  46. using System.Web.UI.Adapters;
  47. using System.Web.UI.WebControls;
  48. using System.Web.Util;
  49. #if NET_4_0
  50. using System.Web.Routing;
  51. #endif
  52. namespace System.Web.UI
  53. {
  54. // CAS
  55. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  56. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  57. // attributes
  58. [DefaultProperty ("ID"), DesignerCategory ("Code"), ToolboxItemFilter ("System.Web.UI", ToolboxItemFilterType.Require)]
  59. [ToolboxItem ("System.Web.UI.Design.WebControlToolboxItem, " + Consts.AssemblySystem_Design)]
  60. [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  61. [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web,
  62. "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
  63. [Bindable (true)]
  64. [Themeable (false)]
  65. public partial class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor, IUrlResolutionService, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
  66. {
  67. internal static readonly object DataBindingEvent = new object ();
  68. internal static readonly object DisposedEvent = new object ();
  69. internal static readonly object InitEvent = new object ();
  70. internal static readonly object LoadEvent = new object ();
  71. internal static readonly object PreRenderEvent = new object ();
  72. internal static readonly object UnloadEvent = new object ();
  73. internal static string [] defaultNameArray;
  74. /* */
  75. int event_mask;
  76. const int databinding_mask = 1;
  77. const int disposed_mask = 1 << 1;
  78. const int init_mask = 1 << 2;
  79. const int load_mask = 1 << 3;
  80. const int prerender_mask = 1 << 4;
  81. const int unload_mask = 1 << 5;
  82. /* */
  83. [ThreadStatic]
  84. static Dictionary <Type, bool> loadViewStateByIDCache;
  85. bool? loadViewStateByID;
  86. string uniqueID;
  87. string clientID;
  88. string _userId;
  89. ControlCollection _controls;
  90. Control _namingContainer;
  91. Page _page;
  92. Control _parent;
  93. ISite _site;
  94. StateBag _viewState;
  95. EventHandlerList _events;
  96. RenderMethod _renderMethodDelegate;
  97. Hashtable _controlsCache;
  98. int defaultNumberID;
  99. DataBindingCollection dataBindings;
  100. Hashtable pendingVS; // may hold unused viewstate data from child controls
  101. TemplateControl _templateControl;
  102. bool _isChildControlStateCleared;
  103. string _templateSourceDirectory;
  104. #if NET_4_0
  105. ViewStateMode viewStateMode;
  106. ClientIDMode? clientIDMode;
  107. ClientIDMode? effectiveClientIDMode;
  108. Version renderingCompatibility;
  109. bool? renderingCompatibilityOld;
  110. #endif
  111. /*************/
  112. int stateMask;
  113. const int ENABLE_VIEWSTATE = 1;
  114. const int VISIBLE = 1 << 1;
  115. const int AUTOID = 1 << 2;
  116. const int CREATING_CONTROLS = 1 << 3;
  117. const int BINDING_CONTAINER = 1 << 4;
  118. const int AUTO_EVENT_WIREUP = 1 << 5;
  119. const int IS_NAMING_CONTAINER = 1 << 6;
  120. const int VISIBLE_CHANGED = 1 << 7;
  121. const int TRACK_VIEWSTATE = 1 << 8;
  122. const int CHILD_CONTROLS_CREATED = 1 << 9;
  123. const int ID_SET = 1 << 10;
  124. const int INITED = 1 << 11;
  125. const int INITING = 1 << 12;
  126. const int VIEWSTATE_LOADED = 1 << 13;
  127. const int LOADED = 1 << 14;
  128. const int PRERENDERED = 1 << 15;
  129. const int ENABLE_THEMING = 1 << 16;
  130. const int AUTOID_SET = 1 << 17;
  131. const int REMOVED = 1 << 18;
  132. /*************/
  133. static Control ()
  134. {
  135. defaultNameArray = new string [100];
  136. for (int i = 0; i < 100; i++)
  137. defaultNameArray [i] = String.Concat ("ctl", i.ToString ("D2"));
  138. }
  139. public Control ()
  140. {
  141. stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
  142. if (this is INamingContainer)
  143. stateMask |= IS_NAMING_CONTAINER;
  144. #if NET_4_0
  145. viewStateMode = ViewStateMode.Inherit;
  146. #endif
  147. }
  148. ControlAdapter adapter;
  149. bool did_adapter_lookup;
  150. protected internal ControlAdapter Adapter {
  151. get {
  152. if (!did_adapter_lookup) {
  153. adapter = ResolveAdapter ();
  154. if (adapter != null)
  155. adapter.control = this;
  156. did_adapter_lookup = true;
  157. }
  158. return adapter;
  159. }
  160. }
  161. string _appRelativeTemplateSourceDirectory = null;
  162. [EditorBrowsable (EditorBrowsableState.Advanced)]
  163. [Browsable (false)]
  164. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  165. public string AppRelativeTemplateSourceDirectory {
  166. get {
  167. if (_appRelativeTemplateSourceDirectory != null)
  168. return _appRelativeTemplateSourceDirectory;
  169. string tempSrcDir = null;
  170. TemplateControl templateControl = TemplateControl;
  171. if (templateControl != null) {
  172. string templateVirtualPath = templateControl.AppRelativeVirtualPath;
  173. if (!String.IsNullOrEmpty (templateVirtualPath))
  174. tempSrcDir = VirtualPathUtility.GetDirectory (templateVirtualPath, false);
  175. }
  176. _appRelativeTemplateSourceDirectory = (tempSrcDir != null) ? tempSrcDir : VirtualPathUtility.ToAppRelative (TemplateSourceDirectory);
  177. return _appRelativeTemplateSourceDirectory;
  178. }
  179. [EditorBrowsable (EditorBrowsableState.Never)]
  180. set {
  181. _appRelativeTemplateSourceDirectory = value;
  182. _templateSourceDirectory = null;
  183. }
  184. }
  185. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  186. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  187. #if NET_4_0
  188. [Bindable (true)]
  189. #endif
  190. public Control BindingContainer {
  191. get {
  192. Control container = NamingContainer;
  193. if (container != null && container is INonBindingContainer || (stateMask & BINDING_CONTAINER) == 0)
  194. container = container.BindingContainer;
  195. return container;
  196. }
  197. }
  198. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  199. [Browsable (false)]
  200. [WebSysDescription ("An Identification of the control that is rendered.")]
  201. public virtual string ClientID {
  202. get {
  203. if (clientID != null)
  204. return clientID;
  205. #if NET_4_0
  206. switch (EffectiveClientIDMode) {
  207. case ClientIDMode.AutoID:
  208. clientID = UniqueID2ClientID (UniqueID);
  209. break;
  210. case ClientIDMode.Predictable:
  211. EnsureID ();
  212. clientID = GeneratePredictableClientID ();
  213. break;
  214. case ClientIDMode.Static:
  215. EnsureID ();
  216. clientID = ID;
  217. break;
  218. }
  219. #else
  220. clientID = UniqueID2ClientID (UniqueID);
  221. #endif
  222. stateMask |= ID_SET;
  223. return clientID;
  224. }
  225. }
  226. #if NET_4_0
  227. [Bindable (false)]
  228. [Browsable (false)]
  229. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  230. public virtual Version RenderingCompatibility {
  231. get {
  232. if (renderingCompatibility == null) {
  233. var ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  234. renderingCompatibility = ps != null ? ps.ControlRenderingCompatibilityVersion : new Version (4, 0);
  235. }
  236. return renderingCompatibility;
  237. }
  238. set {
  239. renderingCompatibility = value;
  240. renderingCompatibilityOld = null;
  241. }
  242. }
  243. internal bool RenderingCompatibilityLessThan40 {
  244. get {
  245. if (!renderingCompatibilityOld.HasValue)
  246. renderingCompatibilityOld = RenderingCompatibility < new Version (4, 0);
  247. return renderingCompatibilityOld.Value;
  248. }
  249. }
  250. [Bindable (false)]
  251. [Browsable (false)]
  252. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  253. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  254. public Control DataItemContainer {
  255. get {
  256. Control container = NamingContainer;
  257. if (container == null)
  258. return null;
  259. if (container is IDataItemContainer)
  260. return container;
  261. return container.DataItemContainer;
  262. }
  263. }
  264. [Bindable (false)]
  265. [Browsable (false)]
  266. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  267. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  268. public Control DataKeysContainer {
  269. get {
  270. Control container = NamingContainer;
  271. if (container == null)
  272. return null;
  273. if (container is IDataKeysControl)
  274. return container;
  275. return container.DataKeysContainer;
  276. }
  277. }
  278. [Themeable (false)]
  279. [DefaultValue (ClientIDMode.Inherit)]
  280. public virtual ClientIDMode ClientIDMode {
  281. get {
  282. if (!clientIDMode.HasValue)
  283. return ClientIDMode.Inherit;
  284. return clientIDMode.Value;
  285. }
  286. set {
  287. if (clientIDMode.HasValue && clientIDMode.Value != value) {
  288. ClearCachedClientID ();
  289. ClearEffectiveClientIDMode ();
  290. clientIDMode = value;
  291. }
  292. }
  293. }
  294. internal ClientIDMode EffectiveClientIDMode {
  295. get {
  296. if (effectiveClientIDMode.HasValue)
  297. return effectiveClientIDMode.Value;
  298. ClientIDMode ret = ClientIDMode;
  299. if (ret != ClientIDMode.Inherit) {
  300. effectiveClientIDMode = ret;
  301. return ret;
  302. }
  303. // not sure about this, but it seems logical as INamingContainer is
  304. // the top of the hierarchy and it should "reset" the mode.
  305. Control container = NamingContainer;
  306. if (container != null) {
  307. effectiveClientIDMode = container.EffectiveClientIDMode;
  308. return effectiveClientIDMode.Value;
  309. }
  310. var ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  311. effectiveClientIDMode = ps.ClientIDMode;
  312. return effectiveClientIDMode.Value;
  313. }
  314. }
  315. protected void ClearCachedClientID ()
  316. {
  317. clientID = null;
  318. if (!HasControls ())
  319. return;
  320. for (int i = 0; i < _controls.Count; i++)
  321. _controls [i].ClearCachedClientID ();
  322. }
  323. protected void ClearEffectiveClientIDMode ()
  324. {
  325. effectiveClientIDMode = null;
  326. if (!HasControls ())
  327. return;
  328. for (int i = 0; i < _controls.Count; i++)
  329. _controls [i].ClearEffectiveClientIDMode ();
  330. }
  331. string GeneratePredictableClientID ()
  332. {
  333. string myID = ID;
  334. char separator = ClientIDSeparator;
  335. var sb = new StringBuilder ();
  336. Control container = NamingContainer;
  337. if (container != null && container != Page) {
  338. string containerID = container.ID;
  339. if (!String.IsNullOrEmpty (containerID)) {
  340. sb.Append (container.ClientID);
  341. sb.Append (separator);
  342. } else
  343. sb.Append (container.GeneratePredictableClientID ());
  344. }
  345. if (String.IsNullOrEmpty (myID))
  346. return sb.ToString ();
  347. sb.Append (myID);
  348. IDataItemContainer dataItemContainer = DataItemContainer as IDataItemContainer;
  349. if (dataItemContainer == null)
  350. return sb.ToString ();
  351. IDataKeysControl dataKeysContainer = DataKeysContainer as IDataKeysControl;
  352. GetDataBoundControlFieldValue (sb, separator, dataItemContainer, dataKeysContainer);
  353. return sb.ToString ();
  354. }
  355. void GetDataBoundControlFieldValue (StringBuilder sb, char separator, IDataItemContainer dataItemContainer, IDataKeysControl dataKeysContainer)
  356. {
  357. if (dataItemContainer is IDataBoundItemControl)
  358. return;
  359. int index = dataItemContainer.DisplayIndex;
  360. if (dataKeysContainer == null) {
  361. if (index >= 0) {
  362. sb.Append (separator);
  363. sb.Append (index);
  364. }
  365. return;
  366. }
  367. string[] suffixes = dataKeysContainer.ClientIDRowSuffix;
  368. DataKeyArray keys = dataKeysContainer.ClientIDRowSuffixDataKeys;
  369. if (keys == null || suffixes == null || suffixes.Length == 0) {
  370. sb.Append (separator);
  371. sb.Append (index);
  372. return;
  373. }
  374. object value;
  375. DataKey key = keys [index];
  376. foreach (string suffix in suffixes) {
  377. sb.Append (separator);
  378. value = key != null ? key [suffix] : null;
  379. if (value == null)
  380. continue;
  381. sb.Append (value.ToString ());
  382. }
  383. }
  384. #endif
  385. internal string UniqueID2ClientID (string uniqueId)
  386. {
  387. if (String.IsNullOrEmpty (uniqueId))
  388. return null;
  389. return uniqueId.Replace (IdSeparator, ClientIDSeparator);
  390. }
  391. protected char ClientIDSeparator {
  392. get { return '_'; }
  393. }
  394. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  395. [Browsable (false)]
  396. [WebSysDescription ("The child controls of this control.")]
  397. public virtual ControlCollection Controls { //DIT
  398. get {
  399. if (_controls == null)
  400. _controls = CreateControlCollection ();
  401. return _controls;
  402. }
  403. }
  404. [MonoTODO ("revisit once we have a real design strategy")]
  405. protected internal bool DesignMode {
  406. get { return false; }
  407. }
  408. [DefaultValue (true), WebCategory ("Behavior")]
  409. [WebSysDescription ("An Identification of the control that is rendered.")]
  410. [Themeable (false)]
  411. public virtual bool EnableViewState {
  412. get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
  413. set { SetMask (ENABLE_VIEWSTATE, value); }
  414. }
  415. [MergableProperty (false), ParenthesizePropertyName (true)]
  416. [WebSysDescription ("The name of the control that is rendered.")]
  417. [Filterable (false), Themeable (false)]
  418. public virtual string ID {
  419. get { return (((stateMask & ID_SET) != 0) ? _userId : null); }
  420. set {
  421. if (value != null && value.Length == 0)
  422. value = null;
  423. stateMask |= ID_SET;
  424. _userId = value;
  425. NullifyUniqueID ();
  426. }
  427. }
  428. protected internal bool IsChildControlStateCleared {
  429. get { return _isChildControlStateCleared; }
  430. }
  431. protected bool LoadViewStateByID {
  432. get {
  433. if (loadViewStateByID == null)
  434. loadViewStateByID = IsLoadViewStateByID ();
  435. return (bool)loadViewStateByID;
  436. }
  437. }
  438. protected internal bool IsViewStateEnabled {
  439. get {
  440. for (Control control = this; control != null; control = control.Parent) {
  441. if (!control.EnableViewState)
  442. return false;
  443. #if NET_4_0
  444. ViewStateMode vsm = control.ViewStateMode;
  445. if (vsm != ViewStateMode.Inherit)
  446. return vsm == ViewStateMode.Enabled;
  447. #endif
  448. }
  449. return true;
  450. }
  451. }
  452. protected char IdSeparator {
  453. get { return '$'; }
  454. }
  455. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  456. [Browsable (false)]
  457. [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
  458. #if NET_4_0
  459. [Bindable (true)]
  460. #endif
  461. public virtual Control NamingContainer {
  462. get {
  463. if (_namingContainer == null && _parent != null) {
  464. if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
  465. _namingContainer = _parent.NamingContainer;
  466. else
  467. _namingContainer = _parent;
  468. }
  469. return _namingContainer;
  470. }
  471. }
  472. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  473. [Browsable (false)]
  474. [WebSysDescription ("The webpage that this control resides on.")]
  475. [Bindable (false)]
  476. public virtual Page Page { //DIT
  477. get {
  478. if (_page == null){
  479. if (NamingContainer != null)
  480. _page = NamingContainer.Page;
  481. else if (Parent != null)
  482. _page = Parent.Page;
  483. }
  484. return _page;
  485. }
  486. set { _page = value; }
  487. }
  488. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  489. [Browsable (false)]
  490. [WebSysDescription ("The parent control of this control.")]
  491. #if NET_4_0
  492. [Bindable (true)]
  493. #endif
  494. public virtual Control Parent { //DIT
  495. get { return _parent; }
  496. }
  497. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  498. [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
  499. [WebSysDescription ("The site this control is part of.")]
  500. public ISite Site { //DIT
  501. get { return _site; }
  502. set { _site = value; }
  503. }
  504. [Browsable (false)]
  505. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  506. #if NET_4_0
  507. [Bindable (true)]
  508. #endif
  509. public TemplateControl TemplateControl {
  510. get { return TemplateControlInternal; }
  511. [EditorBrowsable (EditorBrowsableState.Never)]
  512. set { _templateControl = value; }
  513. }
  514. internal virtual TemplateControl TemplateControlInternal {
  515. get {
  516. if (_templateControl != null)
  517. return _templateControl;
  518. if (_parent != null)
  519. return _parent.TemplateControl;
  520. return null;
  521. }
  522. }
  523. #if !TARGET_J2EE
  524. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  525. [Browsable (false)]
  526. [WebSysDescription ("A virtual directory containing the parent of the control.")]
  527. public virtual string TemplateSourceDirectory {
  528. get {
  529. if (_templateSourceDirectory == null) {
  530. TemplateControl tc = TemplateControl;
  531. if (tc == null) {
  532. HttpContext ctx = Context;
  533. if (ctx != null)
  534. _templateSourceDirectory = VirtualPathUtility.GetDirectory (ctx.Request.CurrentExecutionFilePath);
  535. } else if (tc != this)
  536. _templateSourceDirectory = tc.TemplateSourceDirectory;
  537. if (_templateSourceDirectory == null && this is TemplateControl) {
  538. string path = ((TemplateControl) this).AppRelativeVirtualPath;
  539. if (path != null) {
  540. string ret = VirtualPathUtility.GetDirectory (VirtualPathUtility.ToAbsolute (path));
  541. int len = ret.Length;
  542. if (len <= 1)
  543. return ret;
  544. if (ret [--len] == '/')
  545. _templateSourceDirectory = ret.Substring (0, len);
  546. } else
  547. _templateSourceDirectory = String.Empty;
  548. }
  549. if (_templateSourceDirectory == null)
  550. _templateSourceDirectory = String.Empty;
  551. }
  552. return _templateSourceDirectory;
  553. }
  554. }
  555. #endif
  556. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  557. [Browsable (false)]
  558. [WebSysDescription ("The unique ID of the control.")]
  559. public virtual string UniqueID {
  560. get {
  561. if (uniqueID != null)
  562. return uniqueID;
  563. Control container = NamingContainer;
  564. if (container == null)
  565. return _userId;
  566. EnsureIDInternal ();
  567. string prefix = container.UniqueID;
  568. if (container == Page || prefix == null) {
  569. uniqueID = _userId;
  570. #if TARGET_J2EE
  571. if (getFacesContext () != null)
  572. uniqueID = getFacesContext ().getExternalContext ().encodeNamespace (uniqueID);
  573. #endif
  574. return uniqueID;
  575. }
  576. uniqueID = prefix + IdSeparator + _userId;
  577. return uniqueID;
  578. }
  579. }
  580. void SetMask (int m, bool val) {
  581. if (val)
  582. stateMask |= m;
  583. else
  584. stateMask &= ~m;
  585. }
  586. [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
  587. [WebSysDescription ("Visiblity state of the control.")]
  588. public virtual bool Visible {
  589. get {
  590. if ((stateMask & VISIBLE) == 0)
  591. return false;
  592. if (_parent != null)
  593. return _parent.Visible;
  594. return true;
  595. }
  596. set {
  597. if ((value && (stateMask & VISIBLE) == 0) ||
  598. (!value && (stateMask & VISIBLE) != 0)) {
  599. if (IsTrackingViewState)
  600. stateMask |= VISIBLE_CHANGED;
  601. }
  602. SetMask (VISIBLE, value);
  603. }
  604. }
  605. protected bool ChildControlsCreated {
  606. get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
  607. set {
  608. if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0) {
  609. ControlCollection cc = Controls;
  610. if (cc != null)
  611. cc.Clear ();
  612. }
  613. SetMask (CHILD_CONTROLS_CREATED, value);
  614. }
  615. }
  616. [Browsable (false)]
  617. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  618. protected internal virtual HttpContext Context { //DIT
  619. get {
  620. Page page = Page;
  621. if (page != null)
  622. return page.Context;
  623. return HttpContext.Current;
  624. }
  625. }
  626. protected EventHandlerList Events {
  627. get {
  628. if (_events == null)
  629. _events = new EventHandlerList ();
  630. return _events;
  631. }
  632. }
  633. protected bool HasChildViewState {
  634. get { return (pendingVS != null && pendingVS.Count > 0); }
  635. }
  636. protected bool IsTrackingViewState {
  637. get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
  638. }
  639. [Browsable (false)]
  640. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  641. [WebSysDescription ("ViewState")]
  642. protected virtual StateBag ViewState {
  643. get {
  644. if (_viewState == null)
  645. _viewState = new StateBag (ViewStateIgnoresCase);
  646. if (IsTrackingViewState)
  647. _viewState.TrackViewState ();
  648. return _viewState;
  649. }
  650. }
  651. [Browsable (false)]
  652. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  653. protected virtual bool ViewStateIgnoresCase {
  654. get { return false; }
  655. }
  656. internal bool AutoEventWireup {
  657. get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
  658. set { SetMask (AUTO_EVENT_WIREUP, value); }
  659. }
  660. internal void SetBindingContainer (bool isBC)
  661. {
  662. SetMask (BINDING_CONTAINER, isBC);
  663. }
  664. internal void ResetChildNames ()
  665. {
  666. ResetChildNames (-1);
  667. }
  668. internal void ResetChildNames (int value)
  669. {
  670. if (value < 0)
  671. defaultNumberID = 0;
  672. else
  673. defaultNumberID = value;
  674. }
  675. internal int GetDefaultNumberID ()
  676. {
  677. return defaultNumberID;
  678. }
  679. string GetDefaultName ()
  680. {
  681. string defaultName;
  682. if (defaultNumberID > 99)
  683. defaultName = "ctl" + defaultNumberID++;
  684. else
  685. defaultName = defaultNameArray [defaultNumberID++];
  686. return defaultName;
  687. }
  688. void NullifyUniqueID ()
  689. {
  690. uniqueID = null;
  691. #if NET_4_0
  692. ClearCachedClientID ();
  693. #endif
  694. if (!HasControls ())
  695. return;
  696. for (int i = 0; i < _controls.Count; i++)
  697. _controls [i].NullifyUniqueID ();
  698. }
  699. bool IsLoadViewStateByID ()
  700. {
  701. if (loadViewStateByIDCache == null)
  702. loadViewStateByIDCache = new Dictionary <Type, bool> ();
  703. bool ret;
  704. Type myType = GetType ();
  705. if (loadViewStateByIDCache.TryGetValue (myType, out ret))
  706. return ret;
  707. System.ComponentModel.AttributeCollection attrs = TypeDescriptor.GetAttributes (myType);
  708. if (attrs != null || attrs.Count > 0) {
  709. ret = false;
  710. foreach (Attribute attr in attrs) {
  711. if (attr is ViewStateModeByIdAttribute) {
  712. ret = true;
  713. break;
  714. }
  715. }
  716. } else
  717. ret = false;
  718. loadViewStateByIDCache.Add (myType, ret);
  719. return ret;
  720. }
  721. protected internal virtual void AddedControl (Control control, int index)
  722. {
  723. ResetControlsCache ();
  724. /* Ensure the control don't have more than 1 parent */
  725. if (control._parent != null)
  726. control._parent.Controls.Remove (control);
  727. control._parent = this;
  728. Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
  729. if ((stateMask & (INITING | INITED)) != 0) {
  730. control.InitRecursive (nc);
  731. control.SetMask (REMOVED, false);
  732. } else {
  733. control.SetNamingContainer (nc);
  734. control.SetMask (REMOVED, false);
  735. return;
  736. }
  737. if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
  738. if (pendingVS != null) {
  739. object vs;
  740. bool byId = LoadViewStateByID;
  741. string id;
  742. if (byId) {
  743. control.EnsureID ();
  744. id = control.ID;
  745. vs = pendingVS [id];
  746. } else {
  747. id = null;
  748. vs = pendingVS [index];
  749. }
  750. if (vs != null) {
  751. if (byId)
  752. pendingVS.Remove (id);
  753. else
  754. pendingVS.Remove (index);
  755. if (pendingVS.Count == 0)
  756. pendingVS = null;
  757. control.LoadViewStateRecursive (vs);
  758. }
  759. }
  760. }
  761. if ((stateMask & LOADED) != 0)
  762. control.LoadRecursive ();
  763. if ((stateMask & PRERENDERED) != 0)
  764. control.PreRenderRecursiveInternal ();
  765. }
  766. void SetNamingContainer (Control nc)
  767. {
  768. if (nc != null) {
  769. _namingContainer = nc;
  770. if (AutoID)
  771. EnsureIDInternal ();
  772. }
  773. }
  774. protected virtual void AddParsedSubObject (object obj) //DIT
  775. {
  776. Control c = obj as Control;
  777. if (c != null)
  778. Controls.Add (c);
  779. }
  780. [EditorBrowsable (EditorBrowsableState.Advanced)]
  781. public virtual void ApplyStyleSheetSkin (Page page)
  782. {
  783. if (page == null)
  784. return;
  785. if (!EnableTheming) /* this enough? */
  786. return;
  787. /* apply the style sheet skin here */
  788. if (page.StyleSheetPageTheme != null) {
  789. ControlSkin cs = page.StyleSheetPageTheme.GetControlSkin (GetType (), SkinID);
  790. if (cs != null)
  791. cs.ApplySkin (this);
  792. }
  793. }
  794. [MonoTODO]
  795. protected void BuildProfileTree (string parentId, bool calcViewState)
  796. {
  797. }
  798. protected void ClearChildControlState ()
  799. {
  800. _isChildControlStateCleared = true;
  801. }
  802. protected void ClearChildState ()
  803. {
  804. ClearChildViewState ();
  805. ClearChildControlState ();
  806. }
  807. protected void ClearChildViewState ()
  808. {
  809. pendingVS = null;
  810. }
  811. protected internal virtual void CreateChildControls () //DIT
  812. {
  813. }
  814. protected virtual ControlCollection CreateControlCollection () //DIT
  815. {
  816. return new ControlCollection (this);
  817. }
  818. protected virtual void EnsureChildControls ()
  819. {
  820. if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
  821. stateMask |= CREATING_CONTROLS;
  822. if (Adapter != null)
  823. Adapter.CreateChildControls ();
  824. else
  825. CreateChildControls ();
  826. ChildControlsCreated = true;
  827. stateMask &= ~CREATING_CONTROLS;
  828. }
  829. }
  830. void EnsureIDInternal ()
  831. {
  832. if (_userId != null)
  833. return;
  834. _userId = NamingContainer.GetDefaultName ();
  835. SetMask (AUTOID_SET, true);
  836. }
  837. protected void EnsureID ()
  838. {
  839. if (NamingContainer == null)
  840. return;
  841. EnsureIDInternal ();
  842. SetMask (ID_SET, true);
  843. }
  844. protected bool HasEvents ()
  845. {
  846. return _events != null;
  847. }
  848. void ResetControlsCache ()
  849. {
  850. _controlsCache = null;
  851. if ((this.stateMask & IS_NAMING_CONTAINER) == 0 && Parent != null)
  852. Parent.ResetControlsCache ();
  853. }
  854. Hashtable InitControlsCache ()
  855. {
  856. if (_controlsCache != null)
  857. return _controlsCache;
  858. if ((this.stateMask & IS_NAMING_CONTAINER) != 0 || Parent == null)
  859. //LAMESPEC: MS' docs don't mention it, but FindControl is case insensitive.
  860. _controlsCache = new Hashtable (StringComparer.OrdinalIgnoreCase);
  861. else
  862. _controlsCache = Parent.InitControlsCache ();
  863. return _controlsCache;
  864. }
  865. void EnsureControlsCache ()
  866. {
  867. if (_controlsCache != null)
  868. return;
  869. InitControlsCache ();
  870. FillControlCache (_controls);
  871. }
  872. void FillControlCache (ControlCollection controls)
  873. {
  874. if (controls == null || controls.Count == 0)
  875. return;
  876. foreach (Control c in controls) {
  877. try {
  878. if (c._userId != null)
  879. _controlsCache.Add (c._userId, c);
  880. } catch (ArgumentException) {
  881. throw new HttpException (
  882. "Multiple controls with the same ID '" +
  883. c._userId +
  884. "' were found. FindControl requires that controls have unique IDs. ");
  885. }
  886. if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ())
  887. FillControlCache (c.Controls);
  888. }
  889. }
  890. protected bool IsLiteralContent ()
  891. {
  892. if (_controls != null && _controls.Count == 1 && _controls [0] is LiteralControl)
  893. return true;
  894. return false;
  895. }
  896. [WebSysDescription ("")]
  897. public virtual Control FindControl (string id)
  898. {
  899. return FindControl (id, 0);
  900. }
  901. Control LookForControlByName (string id)
  902. {
  903. EnsureControlsCache ();
  904. return (Control) _controlsCache [id];
  905. }
  906. protected virtual Control FindControl (string id, int pathOffset)
  907. {
  908. EnsureChildControls ();
  909. Control namingContainer = null;
  910. if ((stateMask & IS_NAMING_CONTAINER) == 0) {
  911. namingContainer = NamingContainer;
  912. if (namingContainer == null)
  913. return null;
  914. return namingContainer.FindControl (id, pathOffset);
  915. }
  916. if (!HasControls ())
  917. return null;
  918. int separatorIdx = id.IndexOf (IdSeparator, pathOffset);
  919. if (separatorIdx == -1)
  920. return LookForControlByName (id.Substring (pathOffset));
  921. string idfound = id.Substring (pathOffset, separatorIdx - pathOffset);
  922. namingContainer = LookForControlByName (idfound);
  923. if (namingContainer == null)
  924. return null;
  925. return namingContainer.FindControl (id, separatorIdx + 1);
  926. }
  927. protected virtual void LoadViewState (object savedState)
  928. {
  929. if (savedState != null) {
  930. ViewState.LoadViewState (savedState);
  931. object o = ViewState ["Visible"];
  932. if (o != null) {
  933. SetMask (VISIBLE, (bool) o);
  934. stateMask |= VISIBLE_CHANGED;
  935. }
  936. }
  937. }
  938. // [MonoTODO("Secure?")]
  939. protected string MapPathSecure (string virtualPath)
  940. {
  941. string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
  942. return Context.Request.MapPath (combined);
  943. }
  944. protected virtual bool OnBubbleEvent (object source, EventArgs args) //DIT
  945. {
  946. #if MONO_TRACE
  947. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  948. string type_name = null;
  949. if (trace != null) {
  950. type_name = GetType ().Name;
  951. trace.Write ("control", String.Concat ("OnBubbleEvent ", _userId, " ", type_name));
  952. }
  953. #endif
  954. return false;
  955. }
  956. protected virtual void OnDataBinding (EventArgs e)
  957. {
  958. if ((event_mask & databinding_mask) != 0) {
  959. EventHandler eh = (EventHandler) (_events [DataBindingEvent]);
  960. if (eh != null) {
  961. #if MONO_TRACE
  962. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  963. string type_name = null;
  964. if (trace != null) {
  965. type_name = GetType ().Name;
  966. trace.Write ("control", String.Concat ("OnDataBinding ", _userId, " ", type_name));
  967. }
  968. #endif
  969. eh (this, e);
  970. }
  971. }
  972. }
  973. protected internal virtual void OnInit (EventArgs e)
  974. {
  975. if ((event_mask & init_mask) != 0) {
  976. EventHandler eh = (EventHandler) (_events [InitEvent]);
  977. if (eh != null) {
  978. #if MONO_TRACE
  979. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  980. string type_name = null;
  981. if (trace != null) {
  982. type_name = GetType ().Name;
  983. trace.Write ("control", String.Concat ("OnInit ", _userId, " ", type_name));
  984. }
  985. #endif
  986. eh (this, e);
  987. }
  988. }
  989. }
  990. protected internal virtual void OnLoad (EventArgs e)
  991. {
  992. if ((event_mask & load_mask) != 0) {
  993. EventHandler eh = (EventHandler) (_events [LoadEvent]);
  994. if (eh != null) {
  995. #if MONO_TRACE
  996. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  997. string type_name = null;
  998. if (trace != null) {
  999. type_name = GetType ().Name;
  1000. trace.Write ("control", String.Concat ("OnLoad ", _userId, " ", type_name));
  1001. }
  1002. #endif
  1003. eh (this, e);
  1004. }
  1005. }
  1006. }
  1007. protected internal virtual void OnPreRender (EventArgs e)
  1008. {
  1009. if ((event_mask & prerender_mask) != 0) {
  1010. EventHandler eh = (EventHandler) (_events [PreRenderEvent]);
  1011. if (eh != null) {
  1012. #if MONO_TRACE
  1013. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1014. string type_name = null;
  1015. if (trace != null) {
  1016. type_name = GetType ().Name;
  1017. trace.Write ("control", String.Concat ("OnPreRender ", _userId, " ", type_name));
  1018. }
  1019. #endif
  1020. eh (this, e);
  1021. }
  1022. }
  1023. }
  1024. protected internal virtual void OnUnload (EventArgs e)
  1025. {
  1026. if ((event_mask & unload_mask) != 0) {
  1027. EventHandler eh = (EventHandler) (_events [UnloadEvent]);
  1028. if (eh != null) {
  1029. #if MONO_TRACE
  1030. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1031. string type_name = null;
  1032. if (trace != null) {
  1033. type_name = GetType ().Name;
  1034. trace.Write ("control", String.Concat ("OnUnload ", _userId, " ", type_name));
  1035. }
  1036. #endif
  1037. eh (this, e);
  1038. }
  1039. }
  1040. }
  1041. protected internal Stream OpenFile (string path)
  1042. {
  1043. try {
  1044. string filePath = Context.Server.MapPath (path);
  1045. return File.OpenRead (filePath);
  1046. }
  1047. catch (UnauthorizedAccessException) {
  1048. throw new HttpException ("Access to the specified file was denied.");
  1049. }
  1050. }
  1051. internal string GetPhysicalFilePath (string virtualPath)
  1052. {
  1053. Page page = Page;
  1054. if (VirtualPathUtility.IsAbsolute (virtualPath))
  1055. return page != null ? page.MapPath (virtualPath) : Context.Server.MapPath (virtualPath);
  1056. // We need to determine whether one of our parents is a
  1057. // master page. If so, we need to map the path
  1058. // relatively to the master page and not our containing
  1059. // page/control. This is necessary for cases when a
  1060. // relative path is used in a control placed in a master
  1061. // page and the master page is referenced from a
  1062. // location other than its own. In such cases MS.NET looks
  1063. // for the file in the directory where the master page
  1064. // is.
  1065. //
  1066. // An example of where it is needed is at
  1067. //
  1068. // http://quickstarts.asp.net/QuickStartv20/aspnet/samples/masterpages/masterpages_cs/pages/default.aspx
  1069. //
  1070. MasterPage master = null;
  1071. Control ctrl = Parent;
  1072. while (ctrl != null) {
  1073. if (ctrl is MasterPage) {
  1074. master = ctrl as MasterPage;
  1075. break;
  1076. }
  1077. ctrl = ctrl.Parent;
  1078. }
  1079. string path;
  1080. if (master != null)
  1081. path = VirtualPathUtility.Combine (master.TemplateSourceDirectory + "/", virtualPath);
  1082. else
  1083. path = VirtualPathUtility.Combine (TemplateSourceDirectory + "/", virtualPath);
  1084. return page != null ? page.MapPath (path) : Context.Server.MapPath (path);
  1085. }
  1086. protected void RaiseBubbleEvent (object source, EventArgs args)
  1087. {
  1088. Control c = Parent;
  1089. while (c != null) {
  1090. #if MONO_TRACE
  1091. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1092. string type_name = null;
  1093. if (trace != null) {
  1094. type_name = GetType ().Name;
  1095. trace.Write ("control", String.Concat ("RaiseBubbleEvent ", _userId, " ", type_name));
  1096. }
  1097. #endif
  1098. if (c.OnBubbleEvent (source, args)) {
  1099. #if MONO_TRACE
  1100. if (trace != null)
  1101. trace.Write ("control", String.Concat ("End RaiseBubbleEvent (false) ", _userId, " ", type_name));
  1102. #endif
  1103. break;
  1104. }
  1105. #if MONO_TRACE
  1106. if (trace != null)
  1107. trace.Write ("control", String.Concat ("End RaiseBubbleEvent (true) ", _userId, " ", type_name));
  1108. #endif
  1109. c = c.Parent;
  1110. }
  1111. }
  1112. protected internal virtual void Render (HtmlTextWriter writer) //DIT
  1113. {
  1114. RenderChildren (writer);
  1115. }
  1116. protected internal virtual void RenderChildren (HtmlTextWriter writer) //DIT
  1117. {
  1118. if (_renderMethodDelegate != null) {
  1119. _renderMethodDelegate (writer, this);
  1120. return;
  1121. }
  1122. if (_controls == null)
  1123. return;
  1124. int len = _controls.Count;
  1125. Control c;
  1126. for (int i = 0; i < len; i++) {
  1127. c = _controls [i];
  1128. if (c == null)
  1129. continue;
  1130. ControlAdapter tmp = c.Adapter;
  1131. if (tmp != null)
  1132. c.RenderControl (writer, tmp);
  1133. else
  1134. c.RenderControl (writer);
  1135. }
  1136. }
  1137. protected virtual ControlAdapter ResolveAdapter ()
  1138. {
  1139. HttpContext context = Context;
  1140. if (context == null)
  1141. return null;
  1142. if (!context.Request.BrowserMightHaveAdapters)
  1143. return null;
  1144. // Search up the type hierarchy until we find a control with an adapter.
  1145. IDictionary typeMap = context.Request.Browser.Adapters;
  1146. Type controlType = GetType ();
  1147. Type adapterType = (Type)typeMap [controlType];
  1148. while (adapterType == null && controlType != typeof (Control)) {
  1149. controlType = controlType.BaseType;
  1150. adapterType = (Type)typeMap [controlType];
  1151. }
  1152. ControlAdapter a = null;
  1153. if (adapterType != null)
  1154. a = (ControlAdapter)Activator.CreateInstance (adapterType);
  1155. return a;
  1156. }
  1157. protected virtual object SaveViewState ()
  1158. {
  1159. if ((stateMask & VISIBLE_CHANGED) != 0) {
  1160. ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
  1161. } else if (_viewState == null) {
  1162. return null;
  1163. }
  1164. return _viewState.SaveViewState ();
  1165. }
  1166. protected virtual void TrackViewState ()
  1167. {
  1168. if (_viewState != null)
  1169. _viewState.TrackViewState ();
  1170. stateMask |= TRACK_VIEWSTATE;
  1171. }
  1172. public virtual void Dispose ()
  1173. {
  1174. if ((event_mask & disposed_mask) != 0) {
  1175. EventHandler eh = (EventHandler) (_events [DisposedEvent]);
  1176. if (eh != null)
  1177. eh (this, EventArgs.Empty);
  1178. }
  1179. }
  1180. [WebCategory ("FIXME")]
  1181. [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
  1182. public event EventHandler DataBinding {
  1183. add {
  1184. event_mask |= databinding_mask;
  1185. Events.AddHandler (DataBindingEvent, value);
  1186. }
  1187. remove { Events.RemoveHandler (DataBindingEvent, value); }
  1188. }
  1189. [WebSysDescription ("Raised when the contol is disposed.")]
  1190. public event EventHandler Disposed {
  1191. add {
  1192. event_mask |= disposed_mask;
  1193. Events.AddHandler (DisposedEvent, value);
  1194. }
  1195. remove { Events.RemoveHandler (DisposedEvent, value); }
  1196. }
  1197. [WebSysDescription ("Raised when the page containing the control is initialized.")]
  1198. public event EventHandler Init {
  1199. add {
  1200. event_mask |= init_mask;
  1201. Events.AddHandler (InitEvent, value);
  1202. }
  1203. remove { Events.RemoveHandler (InitEvent, value); }
  1204. }
  1205. [WebSysDescription ("Raised after the page containing the control has been loaded.")]
  1206. public event EventHandler Load {
  1207. add {
  1208. event_mask |= load_mask;
  1209. Events.AddHandler (LoadEvent, value);
  1210. }
  1211. remove { Events.RemoveHandler (LoadEvent, value); }
  1212. }
  1213. [WebSysDescription ("Raised before the page containing the control is rendered.")]
  1214. public event EventHandler PreRender {
  1215. add {
  1216. event_mask |= prerender_mask;
  1217. Events.AddHandler (PreRenderEvent, value);
  1218. }
  1219. remove { Events.RemoveHandler (PreRenderEvent, value); }
  1220. }
  1221. [WebSysDescription ("Raised when the page containing the control is unloaded.")]
  1222. public event EventHandler Unload {
  1223. add {
  1224. event_mask |= unload_mask;
  1225. Events.AddHandler (UnloadEvent, value);
  1226. }
  1227. remove { Events.RemoveHandler (UnloadEvent, value); }
  1228. }
  1229. public virtual void DataBind () //DIT
  1230. {
  1231. DataBind (true);
  1232. }
  1233. protected virtual void DataBindChildren ()
  1234. {
  1235. if (!HasControls ())
  1236. return;
  1237. int len = _controls != null ? _controls.Count : 0;
  1238. for (int i = 0; i < len; i++) {
  1239. Control c = _controls [i];
  1240. c.DataBind ();
  1241. }
  1242. }
  1243. public virtual bool HasControls ()
  1244. {
  1245. return (_controls != null && _controls.Count > 0);
  1246. }
  1247. public virtual void RenderControl (HtmlTextWriter writer)
  1248. {
  1249. if (this.adapter != null) {
  1250. RenderControl (writer, this.adapter);
  1251. return;
  1252. }
  1253. if ((stateMask & VISIBLE) != 0) {
  1254. HttpContext ctx = Context;
  1255. TraceContext trace = (ctx != null) ? ctx.Trace : null;
  1256. int pos = 0;
  1257. if ((trace != null) && trace.IsEnabled)
  1258. pos = ctx.Response.GetOutputByteCount ();
  1259. Render (writer);
  1260. if ((trace != null) && trace.IsEnabled) {
  1261. int size = ctx.Response.GetOutputByteCount () - pos;
  1262. trace.SaveSize (this, size >= 0 ? size : 0);
  1263. }
  1264. }
  1265. }
  1266. protected void RenderControl (HtmlTextWriter writer, ControlAdapter adapter)
  1267. {
  1268. if ((stateMask & VISIBLE) != 0) {
  1269. adapter.BeginRender (writer);
  1270. adapter.Render (writer);
  1271. adapter.EndRender (writer);
  1272. }
  1273. }
  1274. public string ResolveUrl (string relativeUrl)
  1275. {
  1276. if (relativeUrl == null)
  1277. throw new ArgumentNullException ("relativeUrl");
  1278. if (relativeUrl == String.Empty)
  1279. return relativeUrl;
  1280. if (VirtualPathUtility.IsAbsolute (relativeUrl))
  1281. return relativeUrl;
  1282. if (relativeUrl [0] == '#')
  1283. return relativeUrl;
  1284. string ts = AppRelativeTemplateSourceDirectory;
  1285. HttpContext ctx = Context;
  1286. HttpResponse resp = ctx != null ? ctx.Response : null;
  1287. if (ts == null || ts.Length == 0 || resp == null || relativeUrl.IndexOf (':') >= 0)
  1288. return relativeUrl;
  1289. if (!VirtualPathUtility.IsAppRelative (relativeUrl))
  1290. relativeUrl = VirtualPathUtility.Combine (VirtualPathUtility.AppendTrailingSlash (ts), relativeUrl);
  1291. return resp.ApplyAppPathModifier (relativeUrl);
  1292. }
  1293. public string ResolveClientUrl (string relativeUrl)
  1294. {
  1295. if (relativeUrl == null)
  1296. throw new ArgumentNullException ("relativeUrl");
  1297. if (relativeUrl.Length == 0)
  1298. return String.Empty;
  1299. #if TARGET_J2EE
  1300. relativeUrl = ResolveClientUrlInternal (relativeUrl);
  1301. javax.faces.context.FacesContext faces = getFacesContext ();
  1302. if (faces == null)
  1303. return relativeUrl;
  1304. string url;
  1305. if (relativeUrl.IndexOf (':') >= 0)
  1306. url = ResolveAppRelativeFromFullPath (relativeUrl);
  1307. else if (VirtualPathUtility.IsAbsolute (relativeUrl))
  1308. url = VirtualPathUtility.ToAppRelative (relativeUrl);
  1309. else
  1310. return faces.getApplication ().getViewHandler ().getResourceURL (faces, relativeUrl);
  1311. if (VirtualPathUtility.IsAppRelative (url)) {
  1312. url = url.Substring (1);
  1313. url = url.Length == 0 ? "/" : url;
  1314. return faces.getApplication ().getViewHandler ().getResourceURL (faces, url);
  1315. }
  1316. return relativeUrl;
  1317. }
  1318. string ResolveClientUrlInternal (string relativeUrl) {
  1319. if (relativeUrl.StartsWith (J2EE.J2EEConsts.ACTION_URL_PREFIX, StringComparison.Ordinal))
  1320. return CreateActionUrl (relativeUrl.Substring (J2EE.J2EEConsts.ACTION_URL_PREFIX.Length));
  1321. if (relativeUrl.StartsWith (J2EE.J2EEConsts.RENDER_URL_PREFIX, StringComparison.Ordinal))
  1322. return ResolveClientUrl (relativeUrl.Substring (J2EE.J2EEConsts.RENDER_URL_PREFIX.Length));
  1323. #endif
  1324. if (VirtualPathUtility.IsAbsolute (relativeUrl) || relativeUrl.IndexOf (':') >= 0)
  1325. return relativeUrl;
  1326. HttpContext context = Context;
  1327. HttpRequest req = context != null ? context.Request : null;
  1328. if (req != null) {
  1329. string templateSourceDirectory = TemplateSourceDirectory;
  1330. if (templateSourceDirectory == null || templateSourceDirectory.Length == 0)
  1331. return relativeUrl;
  1332. string basePath = req.ClientFilePath;
  1333. if (basePath.Length > 1 && basePath [basePath.Length - 1] != '/')
  1334. basePath = VirtualPathUtility.GetDirectory (basePath, false);
  1335. if (VirtualPathUtility.IsAppRelative (relativeUrl))
  1336. return VirtualPathUtility.MakeRelative (basePath, relativeUrl);
  1337. string templatePath = VirtualPathUtility.AppendTrailingSlash (templateSourceDirectory);
  1338. if (basePath.Length == templatePath.Length && String.CompareOrdinal (basePath, templatePath) == 0)
  1339. return relativeUrl;
  1340. relativeUrl = VirtualPathUtility.Combine (templatePath, relativeUrl);
  1341. return VirtualPathUtility.MakeRelative (basePath, relativeUrl);
  1342. }
  1343. return relativeUrl;
  1344. }
  1345. internal bool HasRenderMethodDelegate ()
  1346. {
  1347. return _renderMethodDelegate != null;
  1348. }
  1349. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1350. public void SetRenderMethodDelegate (RenderMethod renderMethod) //DIT
  1351. {
  1352. _renderMethodDelegate = renderMethod;
  1353. }
  1354. internal void LoadRecursive ()
  1355. {
  1356. #if MONO_TRACE
  1357. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1358. string type_name = null;
  1359. if (trace != null) {
  1360. type_name = GetType ().Name;
  1361. trace.Write ("control", String.Concat ("LoadRecursive ", _userId, " ", type_name));
  1362. }
  1363. #endif
  1364. if (Adapter != null)
  1365. Adapter.OnLoad (EventArgs.Empty);
  1366. else
  1367. OnLoad (EventArgs.Empty);
  1368. int ccount = _controls != null ? _controls.Count : 0;
  1369. for (int i = 0; i < ccount; i++) {
  1370. Control c = _controls [i];
  1371. c.LoadRecursive ();
  1372. }
  1373. #if MONO_TRACE
  1374. if (trace != null)
  1375. trace.Write ("control", String.Concat ("End LoadRecursive ", _userId, " ", type_name));
  1376. #endif
  1377. stateMask |= LOADED;
  1378. }
  1379. internal void UnloadRecursive (Boolean dispose)
  1380. {
  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.Concat ("UnloadRecursive ", _userId, " ", type_name));
  1387. }
  1388. #endif
  1389. int ccount = _controls != null ? _controls.Count : 0;
  1390. for (int i = 0; i < ccount; i++) {
  1391. Control c = _controls [i];
  1392. c.UnloadRecursive (dispose);
  1393. }
  1394. #if MONO_TRACE
  1395. if (trace != null)
  1396. trace.Write ("control", String.Concat ("End UnloadRecursive ", _userId, " ", type_name));
  1397. #endif
  1398. ControlAdapter tmp = Adapter;
  1399. if (tmp != null)
  1400. tmp.OnUnload (EventArgs.Empty);
  1401. else
  1402. OnUnload (EventArgs.Empty);
  1403. if (dispose)
  1404. Dispose ();
  1405. }
  1406. internal void PreRenderRecursiveInternal ()
  1407. {
  1408. bool visible;
  1409. visible = Visible;
  1410. if (visible) {
  1411. SetMask (VISIBLE, true);
  1412. EnsureChildControls ();
  1413. #if MONO_TRACE
  1414. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1415. string type_name = null;
  1416. if (trace != null) {
  1417. type_name = GetType ().Name;
  1418. trace.Write ("control", String.Concat ("PreRenderRecursive ", _userId, " ", type_name));
  1419. }
  1420. #endif
  1421. if (Adapter != null)
  1422. Adapter.OnPreRender (EventArgs.Empty);
  1423. else
  1424. OnPreRender (EventArgs.Empty);
  1425. if (!HasControls ())
  1426. return;
  1427. int len = _controls != null ? _controls.Count : 0;
  1428. for (int i = 0; i < len; i++) {
  1429. Control c = _controls [i];
  1430. c.PreRenderRecursiveInternal ();
  1431. }
  1432. #if MONO_TRACE
  1433. if (trace != null)
  1434. trace.Write ("control", String.Concat ("End PreRenderRecursive ", _userId, " ", type_name));
  1435. #endif
  1436. } else
  1437. SetMask (VISIBLE, false);
  1438. stateMask |= PRERENDERED;
  1439. }
  1440. internal void InitRecursive (Control namingContainer)
  1441. {
  1442. #if MONO_TRACE
  1443. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1444. string type_name = null;
  1445. if (trace != null) {
  1446. type_name = GetType ().Name;
  1447. trace.Write ("control", String.Concat ("InitRecursive ", _userId, " ", type_name));
  1448. }
  1449. #endif
  1450. SetNamingContainer (namingContainer);
  1451. if (HasControls ()) {
  1452. if ((stateMask & IS_NAMING_CONTAINER) != 0)
  1453. namingContainer = this;
  1454. int len = _controls != null ? _controls.Count : 0;
  1455. for (int i = 0; i < len; i++) {
  1456. Control c = _controls [i];
  1457. c.InitRecursive (namingContainer);
  1458. }
  1459. }
  1460. if ((stateMask & REMOVED) == 0 && (stateMask & INITED) != INITED) {
  1461. stateMask |= INITING;
  1462. ApplyTheme ();
  1463. ControlAdapter tmp = Adapter;
  1464. if (tmp != null)
  1465. tmp.OnInit (EventArgs.Empty);
  1466. else
  1467. OnInit (EventArgs.Empty);
  1468. TrackViewState ();
  1469. stateMask |= INITED;
  1470. stateMask &= ~INITING;
  1471. }
  1472. #if MONO_TRACE
  1473. if (trace != null)
  1474. trace.Write ("control", String.Concat ("End InitRecursive ", _userId, " ", type_name));
  1475. #endif
  1476. }
  1477. internal object SaveViewStateRecursive ()
  1478. {
  1479. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1480. #if MONO_TRACE
  1481. string type_name = null;
  1482. if (trace != null) {
  1483. type_name = GetType ().Name;
  1484. trace.Write ("control", String.Concat ("SaveViewStateRecursive ", _userId, " ", type_name));
  1485. }
  1486. #endif
  1487. ArrayList controlStates = null;
  1488. bool byId = LoadViewStateByID;
  1489. if (HasControls ()) {
  1490. int len = _controls != null ? _controls.Count : 0;
  1491. for (int i = 0; i < len; i++) {
  1492. Control ctrl = _controls [i];
  1493. object ctrlState = ctrl.SaveViewStateRecursive ();
  1494. if (ctrlState == null)
  1495. continue;
  1496. if (controlStates == null)
  1497. controlStates = new ArrayList ();
  1498. if (byId) {
  1499. ctrl.EnsureID ();
  1500. controlStates.Add (new Pair (ctrl.ID, ctrlState));
  1501. } else
  1502. controlStates.Add (new Pair (i, ctrlState));
  1503. }
  1504. }
  1505. object thisAdapterViewState = null;
  1506. if (Adapter != null)
  1507. thisAdapterViewState = Adapter.SaveAdapterViewState ();
  1508. object thisState = null;
  1509. if (IsViewStateEnabled)
  1510. thisState = SaveViewState ();
  1511. if (thisState == null && controlStates == null) {
  1512. if (trace != null) {
  1513. #if MONO_TRACE
  1514. trace.Write ("control", "End SaveViewStateRecursive " + _userId + " " + type_name + " saved nothing");
  1515. #endif
  1516. trace.SaveViewState (this, null);
  1517. }
  1518. return null;
  1519. }
  1520. if (trace != null) {
  1521. #if MONO_TRACE
  1522. trace.Write ("control", "End SaveViewStateRecursive " + _userId + " " + type_name + " saved a Triplet");
  1523. #endif
  1524. trace.SaveViewState (this, thisState);
  1525. }
  1526. thisState = new object[] { thisState, thisAdapterViewState };
  1527. return new Pair (thisState, controlStates);
  1528. }
  1529. internal void LoadViewStateRecursive (object savedState)
  1530. {
  1531. if (savedState == null)
  1532. return;
  1533. #if MONO_TRACE
  1534. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1535. string type_name = null;
  1536. if (trace != null) {
  1537. type_name = GetType ().Name;
  1538. trace.Write ("control", String.Concat ("LoadViewStateRecursive ", _userId, " ", type_name));
  1539. }
  1540. #endif
  1541. Pair savedInfo = (Pair) savedState;
  1542. object[] controlAndAdapterViewStates = (object [])savedInfo.First;
  1543. if (Adapter != null)
  1544. Adapter.LoadAdapterViewState (controlAndAdapterViewStates [1]);
  1545. LoadViewState (controlAndAdapterViewStates [0]);
  1546. ArrayList controlStates = savedInfo.Second as ArrayList;
  1547. if (controlStates == null)
  1548. return;
  1549. int nControls = controlStates.Count;
  1550. bool byId = LoadViewStateByID;
  1551. for (int i = 0; i < nControls; i++) {
  1552. Pair p = controlStates [i] as Pair;
  1553. if (p == null)
  1554. continue;
  1555. if (byId) {
  1556. string id = (string)p.First;
  1557. bool found = false;
  1558. foreach (Control c in Controls) {
  1559. c.EnsureID ();
  1560. if (c.ID == id) {
  1561. found = true;
  1562. c.LoadViewStateRecursive (p.Second);
  1563. break;
  1564. }
  1565. }
  1566. if (!found) {
  1567. if (pendingVS == null)
  1568. pendingVS = new Hashtable ();
  1569. pendingVS [id] = p.Second;
  1570. }
  1571. } else {
  1572. int k = (int) p.First;
  1573. if (k < Controls.Count) {
  1574. Control c = Controls [k];
  1575. c.LoadViewStateRecursive (p.Second);
  1576. } else {
  1577. if (pendingVS == null)
  1578. pendingVS = new Hashtable ();
  1579. pendingVS [k] = p.Second;
  1580. }
  1581. }
  1582. }
  1583. #if MONO_TRACE
  1584. if (trace != null)
  1585. trace.Write ("control", String.Concat ("End LoadViewStateRecursive ", _userId, " ", type_name));
  1586. #endif
  1587. stateMask |= VIEWSTATE_LOADED;
  1588. }
  1589. internal ControlSkin controlSkin;
  1590. internal void ApplyTheme ()
  1591. {
  1592. #if MONO_TRACE
  1593. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  1594. string type_name = null;
  1595. if (trace != null) {
  1596. type_name = GetType ().Name;
  1597. trace.Write ("control", String.Concat ("ApplyThemeRecursive ", _userId, " ", type_name));
  1598. }
  1599. #endif
  1600. Page page = Page;
  1601. if (page != null && page.PageTheme != null && EnableTheming) {
  1602. ControlSkin controlSkin = page.PageTheme.GetControlSkin (GetType (), SkinID);
  1603. if (controlSkin != null)
  1604. controlSkin.ApplySkin (this);
  1605. }
  1606. #if MONO_TRACE
  1607. if (trace != null)
  1608. trace.Write ("control", String.Concat ("End ApplyThemeRecursive ", _userId, " ", type_name));
  1609. #endif
  1610. }
  1611. internal bool AutoID {
  1612. get { return (stateMask & AUTOID) != 0; }
  1613. set {
  1614. if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
  1615. return;
  1616. SetMask (AUTOID, value);
  1617. }
  1618. }
  1619. protected internal virtual void RemovedControl (Control control)
  1620. {
  1621. control.UnloadRecursive (false);
  1622. control._parent = null;
  1623. control._page = null;
  1624. control._namingContainer = null;
  1625. if ((control.stateMask & AUTOID_SET) != 0) {
  1626. control._userId = null;
  1627. control.SetMask (ID_SET, false);
  1628. }
  1629. control.NullifyUniqueID ();
  1630. control.SetMask (REMOVED, true);
  1631. ResetControlsCache ();
  1632. }
  1633. string skinId = string.Empty;
  1634. bool _enableTheming = true;
  1635. [Browsable (false)]
  1636. [Themeable (false)]
  1637. [DefaultValue (true)]
  1638. public virtual bool EnableTheming {
  1639. get {
  1640. if ((stateMask & ENABLE_THEMING) != 0)
  1641. return _enableTheming;
  1642. if (_parent != null)
  1643. return _parent.EnableTheming;
  1644. return true;
  1645. }
  1646. set {
  1647. SetMask (ENABLE_THEMING, true);
  1648. _enableTheming = value;
  1649. }
  1650. }
  1651. [Browsable (false)]
  1652. [DefaultValue ("")]
  1653. [Filterable (false)]
  1654. public virtual string SkinID {
  1655. get { return skinId; }
  1656. set { skinId = value; }
  1657. }
  1658. ControlBuilder IControlBuilderAccessor.ControlBuilder {
  1659. get { throw new NotImplementedException (); }
  1660. }
  1661. IDictionary IControlDesignerAccessor.GetDesignModeState ()
  1662. {
  1663. throw new NotImplementedException ();
  1664. }
  1665. void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
  1666. {
  1667. SetDesignModeState (designData);
  1668. }
  1669. void IControlDesignerAccessor.SetOwnerControl (Control control)
  1670. {
  1671. throw new NotImplementedException ();
  1672. }
  1673. IDictionary IControlDesignerAccessor.UserData {
  1674. get { throw new NotImplementedException (); }
  1675. }
  1676. ExpressionBindingCollection expressionBindings;
  1677. ExpressionBindingCollection IExpressionsAccessor.Expressions {
  1678. get {
  1679. if (expressionBindings == null)
  1680. expressionBindings = new ExpressionBindingCollection ();
  1681. return expressionBindings;
  1682. }
  1683. }
  1684. bool IExpressionsAccessor.HasExpressions {
  1685. get { return (expressionBindings != null && expressionBindings.Count > 0); }
  1686. }
  1687. public virtual void Focus ()
  1688. {
  1689. Page.SetFocus (this);
  1690. }
  1691. protected internal virtual void LoadControlState (object state)
  1692. {
  1693. }
  1694. protected internal virtual object SaveControlState ()
  1695. {
  1696. return null;
  1697. }
  1698. protected virtual void DataBind (bool raiseOnDataBinding)
  1699. {
  1700. bool foundDataItem = false;
  1701. if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
  1702. object o = DataBinder.GetDataItem (this, out foundDataItem);
  1703. if (foundDataItem)
  1704. Page.PushDataItemContext (o);
  1705. }
  1706. try {
  1707. if (raiseOnDataBinding)
  1708. OnDataBinding (EventArgs.Empty);
  1709. DataBindChildren ();
  1710. } finally {
  1711. if (foundDataItem)
  1712. Page.PopDataItemContext ();
  1713. }
  1714. }
  1715. protected virtual IDictionary GetDesignModeState ()
  1716. {
  1717. throw new NotImplementedException ();
  1718. }
  1719. protected virtual void SetDesignModeState (IDictionary data)
  1720. {
  1721. throw new NotImplementedException ();
  1722. }
  1723. internal bool IsInited {
  1724. get { return (stateMask & INITED) != 0; }
  1725. }
  1726. internal bool IsLoaded {
  1727. get { return (stateMask & LOADED) != 0; }
  1728. }
  1729. internal bool IsPrerendered {
  1730. get { return (stateMask & PRERENDERED) != 0; }
  1731. }
  1732. bool CheckForValidationSupport ()
  1733. {
  1734. return GetType ().GetCustomAttributes (typeof (SupportsEventValidationAttribute), false).Length > 0;
  1735. }
  1736. //
  1737. // Apparently this is where .NET routes validation from all the controls which
  1738. // support it. See:
  1739. //
  1740. // http://odetocode.com/Blogs/scott/archive/2006/03/20/3145.aspx
  1741. // Sample in here contains ValidateEvent in the stack trace
  1742. //
  1743. // http://odetocode.com/blogs/scott/archive/2006/03/21/3153.aspx
  1744. //
  1745. // http://www.alexthissen.nl/blogs/main/archive/2005/12/13/event-validation-of-controls-in-asp-net-2-0.aspx
  1746. //
  1747. // It also seems that it's the control's responsibility to call this method or
  1748. // validation won't take place. Also, the SupportsEventValidation attribute must be
  1749. // present on the control for validation to take place.
  1750. //
  1751. internal void ValidateEvent (String uniqueId, String argument)
  1752. {
  1753. Page page = Page;
  1754. if (page != null && CheckForValidationSupport ())
  1755. page.ClientScript.ValidateEvent (uniqueId, argument);
  1756. }
  1757. void IParserAccessor.AddParsedSubObject (object obj)
  1758. {
  1759. this.AddParsedSubObject (obj);
  1760. }
  1761. DataBindingCollection IDataBindingsAccessor.DataBindings {
  1762. get {
  1763. if (dataBindings == null) {
  1764. dataBindings = new DataBindingCollection ();
  1765. }
  1766. return dataBindings;
  1767. }
  1768. }
  1769. bool IDataBindingsAccessor.HasDataBindings {
  1770. get {
  1771. if (dataBindings != null && dataBindings.Count > 0) {
  1772. return true;
  1773. }
  1774. return false;
  1775. }
  1776. }
  1777. #if NET_4_0
  1778. [ThemeableAttribute(false)]
  1779. [DefaultValue ("0")]
  1780. public virtual ViewStateMode ViewStateMode {
  1781. get { return viewStateMode; }
  1782. set {
  1783. if (value < ViewStateMode.Inherit || value > ViewStateMode.Disabled)
  1784. throw new ArgumentOutOfRangeException ("An attempt was made to set this property to a value that is not in the ViewStateMode enumeration.");
  1785. viewStateMode = value;
  1786. }
  1787. }
  1788. public string GetRouteUrl (object routeParameters)
  1789. {
  1790. return GetRouteUrl (null, new RouteValueDictionary (routeParameters));
  1791. }
  1792. public string GetRouteUrl (RouteValueDictionary routeParameters)
  1793. {
  1794. return GetRouteUrl (null, routeParameters);
  1795. }
  1796. public string GetRouteUrl (string routeName, object routeParameters)
  1797. {
  1798. return GetRouteUrl (routeName, new RouteValueDictionary (routeParameters));
  1799. }
  1800. public string GetRouteUrl (string routeName, RouteValueDictionary routeParameters)
  1801. {
  1802. HttpContext ctx = Context ?? HttpContext.Current;
  1803. HttpRequest req = ctx != null ? ctx.Request : null;
  1804. if (req == null)
  1805. return null;
  1806. VirtualPathData vpd = RouteTable.Routes.GetVirtualPath (req.RequestContext, routeName, routeParameters);
  1807. if (vpd == null)
  1808. return null;
  1809. return vpd.VirtualPath;
  1810. }
  1811. public string GetUniqueIDRelativeTo (Control control)
  1812. {
  1813. if (control == null)
  1814. throw new ArgumentNullException ("control");
  1815. Control parent = this;
  1816. Page page = Page;
  1817. Control namingContainer = control.NamingContainer;
  1818. if (namingContainer != null)
  1819. while (parent != null && parent != namingContainer)
  1820. parent = parent.Parent;
  1821. if (parent != namingContainer)
  1822. throw new InvalidOperationException (
  1823. String.Format ("This control is not a descendant of the NamingContainer of '{0}'", control.UniqueID)
  1824. );
  1825. int idx = control.UniqueID.LastIndexOf (IdSeparator);
  1826. if (idx < 0)
  1827. return UniqueID;
  1828. return UniqueID.Substring (idx + 1);
  1829. }
  1830. #endif
  1831. }
  1832. }