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