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