* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / System.Web.UI / Control.cs
index 96ec5fee77b77105bf0a4222f074e62ee345220a..83521a7b9de50cf2437e09220253e95467f7da32 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
+// This will provide extra information when trace is enabled. Might be too verbose.
+#define MONO_TRACE
+
 using System.Collections;
 using System.ComponentModel;
 using System.ComponentModel.Design;
 using System.ComponentModel.Design.Serialization;
+using System.Security.Permissions;
 using System.Web;
 using System.Web.Util;
+#if NET_2_0
+using System.Web.UI.Adapters;
+using System.IO;
+#endif
 
 namespace System.Web.UI
 {
+       // CAS
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       // attributes
        [DefaultProperty ("ID"), DesignerCategory ("Code"), ToolboxItemFilter ("System.Web.UI", ToolboxItemFilterType.Require)]
        [ToolboxItem ("System.Web.UI.Design.WebControlToolboxItem, " + Consts.AssemblySystem_Design)]
        [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+#if NET_2_0
+       [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web,
+                               "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
+       [Bindable (true)]
+       [Themeable (false)]
+#else
        [DesignerSerializer ("Microsoft.VSDesigner.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner,
                                "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
+#endif         
         public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
 #if NET_2_0
         , IUrlResolutionService, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
@@ -60,11 +78,20 @@ namespace System.Web.UI
                static readonly object PreRenderEvent = new object();
                static readonly object UnloadEvent = new object();
                static string[] defaultNameArray;
+               /* */
+               int event_mask;
+               const int databinding_mask = 1;
+               const int disposed_mask = 1 << 1;
+               const int init_mask = 1 << 2;
+               const int load_mask = 1 << 3;
+               const int prerender_mask = 1 << 4;
+               const int unload_mask = 1 << 5;
+               /* */
 
                string uniqueID;
                string _userId;
+               TemplateControl _templateControl;
                ControlCollection _controls;
-               IDictionary _childViewStates;
                Control _namingContainer;
                Page _page;
                Control _parent;
@@ -98,7 +125,7 @@ namespace System.Web.UI
                const int LOADED                = 1 << 14;
                const int PRERENDERED           = 1 << 15;
 #if NET_2_0
-               const int ENABLE_THEMING        = 1 << 15;
+               const int ENABLE_THEMING        = 1 << 16;
 #endif
                /*************/
                
@@ -106,7 +133,7 @@ namespace System.Web.UI
                {
                        defaultNameArray = new string [100];
                        for (int i = 0 ; i < 100 ; i++)
-                               defaultNameArray [i] = "_ctrl" + i;
+                               defaultNameArray [i] = "_ctl" + i;
                }
 
                 public Control()
@@ -114,14 +141,49 @@ namespace System.Web.UI
                        stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
                         if (this is INamingContainer)
                                stateMask |= IS_NAMING_CONTAINER;
+#if NET_2_0
+                       stateMask |= ENABLE_THEMING;
+#endif
                 }
 
+#if NET_2_0
+               [MonoTODO]
+               protected ControlAdapter Adapter 
+               {
+                       get {
+                               // for the time being, fool the
+                               // Control machinery into thinking we
+                               // don't have an Adapter.  This will
+                               // allow us to write all the rest of
+                               // the Adapter handling code without
+                               // having to worry about *having*
+                               // adapters.
+                               return null;
+                       }
+               }
+
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-               [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]\r
+               public string AppRelativeTemplateSourceDirectory 
+               {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+                       [EditorBrowsable (EditorBrowsableState.Never)]
+                       set {
+                               throw new NotImplementedException ();
+                       }
+               }
+               
+#endif         
+
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
                public Control BindingContainer {
                        get {
                                Control container = NamingContainer;
-                               if ((container.stateMask & BINDING_CONTAINER) == 0)
+                               if (container != null && (container.stateMask & BINDING_CONTAINER) == 0)
                                        container = container.BindingContainer;
                                return container;
                        }
@@ -129,34 +191,51 @@ namespace System.Web.UI
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]
-               [WebSysDescription ("An Identification of the control that is rendered.")]\r
-               public virtual string ClientID {\r
-                       get {\r
-                               string client = UniqueID;\r
-\r
-                               if (client != null)\r
-                                       client = client.Replace (':', '_');\r
-\r
-                               return client;\r
-                       }\r
-               }\r
+               [WebSysDescription ("An Identification of the control that is rendered.")]
+               public virtual string ClientID {
+                       get {
+                               string client = UniqueID;
+
+                               if (client != null)
+                                       client = client.Replace (':', '_');
+
+                               return client;
+                       }
+               }
+
+#if NET_2_0
+               protected char ClientIDSeparator 
+               {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+#endif         
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]
-               [WebSysDescription ("The child controls of this control.")]\r
-                public virtual ControlCollection Controls //DIT\r
-                {\r
-                        get\r
-                        {\r
-                                if (_controls == null) _controls = CreateControlCollection();\r
-                                return _controls;\r
-                        }\r
+               [WebSysDescription ("The child controls of this control.")]
+                public virtual ControlCollection Controls //DIT
+                {
+                        get
+                        {
+                                if (_controls == null) _controls = CreateControlCollection();
+                                return _controls;
+                        }
                 }
 
+#if NET_2_0
+               [MonoTODO ("revisit once we have a real design strategy")]
+               protected internal bool DesignMode 
+               {
+                       get { return false; }
+               }
+#endif         
+
                [DefaultValue (true), WebCategory ("Behavior")]
-               [WebSysDescription ("An Identification of the control that is rendered.")]\r
+               [WebSysDescription ("An Identification of the control that is rendered.")]
 #if NET_2_0
-               [Themeable (true)]
+               [Themeable (false)]
 #endif                
                 public virtual bool EnableViewState {
                         get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
@@ -164,29 +243,66 @@ namespace System.Web.UI
                 }
                
                [MergableProperty (false), ParenthesizePropertyName (true)]
-               [WebSysDescription ("The name of the control that is rendered.")]\r
+               [WebSysDescription ("The name of the control that is rendered.")]
 #if NET_2_0
-               [Filterable (true), Themeable (true)]
+               [Filterable (false), Themeable (false)]
 #endif                
 
-                public virtual string ID {\r
-                        get {\r
+                public virtual string ID {
+                        get {
                                return (((stateMask & ID_SET) != 0) ? _userId : null);
-                        }\r
-                       \r
-                        set {\r
-                               if (value == "")\r
-                                       value = null;\r
-\r
+                        }
+                       
+                        set {
+                               if (value == "")
+                                       value = null;
+
                                stateMask |= ID_SET;
-                                _userId = value;\r
-                               NullifyUniqueID ();\r
-                        }\r
-                }\r
+                                _userId = value;
+                               NullifyUniqueID ();
+                        }
+                }
+
+#if NET_2_0
+               protected char IdSeparator 
+               {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+
+               protected internal bool IsChildControlStateCleared 
+               {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+
+               protected internal bool IsViewStateEnabled 
+               {
+                       get {
+                               if (Page == null)
+                                       return false;
+
+                               for (Control control = this; control != null; control = control.Parent)
+                                       if (!control.EnableViewState)
+                                               return false;
+
+                               return true;
+                       }
+               }
+
+               protected bool LoadViewStateByID 
+               {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+#endif         
                
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]
-               [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]\r
+               [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
                 public virtual Control NamingContainer {
                         get {
                                 if (_namingContainer == null && _parent != null) {
@@ -197,53 +313,68 @@ namespace System.Web.UI
                                 }
 
                                 return _namingContainer;
-                        }\r
+                        }
                 }
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]
-               [WebSysDescription ("The webpage that this control resides on.")]\r
+               [WebSysDescription ("The webpage that this control resides on.")]
 #if NET_2_0
-               [Bindable (true)]
+               [Bindable (false)]
 #endif                
-               public virtual Page Page //DIT\r
-                {\r
-                        get\r
-                        {\r
-                                if (_page == null && _parent != null) _page = _parent.Page;\r
-                                return _page;\r
-                        }\r
-                        set\r
-                        {\r
-                                _page = value;\r
-                        }\r
+               public virtual Page Page //DIT
+                {
+                        get
+                        {
+                                if (_page == null && _parent != null) _page = _parent.Page;
+                                return _page;
+                        }
+                        set
+                        {
+                                _page = value;
+                        }
                 }
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]
-               [WebSysDescription ("The parent control of this control.")]\r
-                public virtual Control Parent //DIT\r
-                {\r
-                        get\r
-                        {\r
-                                return _parent;\r
-                        }\r
+               [WebSysDescription ("The parent control of this control.")]
+                public virtual Control Parent //DIT
+                {
+                        get
+                        {
+                                return _parent;
+                        }
                 }
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
-               [WebSysDescription ("The site this control is part of.")]\r
-                public ISite Site //DIT\r
-                {\r
-                        get\r
-                        {\r
-                                return _site;\r
-                        }\r
-                        set\r
-                        {\r
-                                _site = value;\r
-                        }\r
-                }\r
+               [WebSysDescription ("The site this control is part of.")]
+                public ISite Site //DIT
+                {
+                        get
+                        {
+                                return _site;
+                        }
+                        set
+                        {
+                                _site = value;
+                        }
+                }
+
+#if NET_2_0
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               public TemplateControl TemplateControl 
+               {
+                       get {
+                               return _templateControl;
+                       }
+                       [EditorBrowsable (EditorBrowsableState.Never)]
+                       set {
+                               _templateControl = value;
+                       }
+               }
+#endif         
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]
@@ -254,28 +385,31 @@ namespace System.Web.UI
 
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]
-               [WebSysDescription ("The unique ID of the control.")]\r
-                public virtual string UniqueID {\r
-                        get {\r
-                               if (uniqueID != null)\r
-                                       return uniqueID;\r
-\r
-                               if (_namingContainer == null) {\r
-                                       return _userId;\r
-                               }\r
-\r
-                               if (_userId == null)\r
-                                       _userId = _namingContainer.GetDefaultName ();\r
-\r
-                               string prefix = _namingContainer.UniqueID;\r
-                               if (_namingContainer == _page || prefix == null) {\r
-                                       uniqueID = _userId;\r
-                                       return uniqueID;\r
-                               }\r
-\r
-                               uniqueID = prefix + ":" + _userId;\r
-                               return uniqueID;\r
-                        }\r
+               [WebSysDescription ("The unique ID of the control.")]
+                public virtual string UniqueID {
+                        get {
+                               if (uniqueID != null)
+                                       return uniqueID;
+
+                               if (_namingContainer == null) {
+                                       if ((stateMask & IS_NAMING_CONTAINER) == 0)
+                                               _namingContainer = NamingContainer;
+                                       if (_namingContainer == null)
+                                               return _userId;
+                               }
+
+                               if (_userId == null)
+                                       _userId = _namingContainer.GetDefaultName ();
+
+                               string prefix = _namingContainer.UniqueID;
+                               if (_namingContainer == _page || prefix == null) {
+                                       uniqueID = _userId;
+                                       return uniqueID;
+                               }
+
+                               uniqueID = prefix + ":" + _userId;
+                               return uniqueID;
+                        }
                 }
 
                void SetMask (int m, bool val)
@@ -288,9 +422,6 @@ namespace System.Web.UI
                
                [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
                [WebSysDescription ("Visiblity state of the control.")]
-#if NET_2_0
-               [Localizable (true)]            
-#endif
                 public virtual bool Visible {
                         get {
                                if ((stateMask & VISIBLE) == 0)
@@ -316,8 +447,10 @@ namespace System.Web.UI
                 protected bool ChildControlsCreated {
                         get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
                         set {
-                               if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0)
-                                       Controls.Clear();
+                               if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0) {
+                                       if (_controls != null)
+                                               _controls.Clear();
+                               }
 
                                SetMask (CHILD_CONTROLS_CREATED, value);
                         }
@@ -325,71 +458,66 @@ namespace System.Web.UI
 
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-                protected virtual HttpContext Context //DIT\r
-                {\r
-                        get\r
-                        {\r
-                                HttpContext context;\r
-                                if (_context != null)\r
-                                        return _context;\r
-                                if (_parent == null)\r
-                                        return HttpContext.Current;\r
-                                context = _parent.Context;\r
-                                if (context != null)\r
-                                        return context;\r
-                                return HttpContext.Current;\r
-                        }\r
-                }\r
-                protected EventHandlerList Events //DIT\r
-                {\r
-                        get\r
-                        {\r
-                                if (_events == null)\r
-                                {\r
-                                       _events = new EventHandlerList();\r
-                                }\r
-                                return _events;\r
-                        }\r
-                }\r
-                protected bool HasChildViewState //DIT\r
-                {\r
-                        get\r
-                        {\r
-                                if (_childViewStates == null) return false;\r
-                                return true;\r
-                        }\r
-                }\r
-
-                protected bool IsTrackingViewState {\r
+                protected virtual HttpContext Context //DIT
+                {
+                        get
+                        {
+                                HttpContext context;
+                                if (_context != null)
+                                        return _context;
+                                if (_parent == null)
+                                        return HttpContext.Current;
+                                context = _parent.Context;
+                                if (context != null)
+                                        return context;
+                                return HttpContext.Current;
+                        }
+                }
+
+                protected EventHandlerList Events {
+                        get {
+                                if (_events == null)
+                                       _events = new EventHandlerList ();
+                                return _events;
+                        }
+                }
+
+                protected bool HasChildViewState {
+                        get {
+                               return (pendingVS != null && pendingVS.Count > 0);
+                        }
+                }
+
+                protected bool IsTrackingViewState {
                         get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
                 }
 
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [WebSysDescription ("ViewState")]
-                protected virtual StateBag ViewState\r
-                {\r
-                        get\r
-                        {\r
-                               if(_viewState == null)\r
-                                       _viewState = new StateBag (ViewStateIgnoresCase);\r
-\r
-                               if (IsTrackingViewState)\r
-                                       _viewState.TrackViewState ();\r
-\r
-                               return _viewState;\r
-                        }\r
-                }\r
-\r
+                protected virtual StateBag ViewState
+                {
+                        get
+                        {
+                               if(_viewState == null)
+                                       _viewState = new StateBag (ViewStateIgnoresCase);
+
+                               if (IsTrackingViewState)
+                                       _viewState.TrackViewState ();
+
+                               return _viewState;
+                        }
+                }
+
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-                protected virtual bool ViewStateIgnoresCase\r
-                {\r
-                        get {\r
-                                return false;\r
-                        }\r
-                }\r
-\r
+                protected virtual bool ViewStateIgnoresCase
+                {
+                        get {
+                                return false;
+                        }
+                }
+
                internal bool AutoEventWireup {
                        get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
                        set { SetMask (AUTO_EVENT_WIREUP, value); }
@@ -400,34 +528,34 @@ namespace System.Web.UI
                        SetMask (BINDING_CONTAINER, isBC);
                }
 
-               internal void ResetChildNames ()\r
-               {\r
-                       defaultNumberID = 0;\r
-               }\r
+               internal void ResetChildNames ()
+               {
+                       defaultNumberID = 0;
+               }
 
                string GetDefaultName ()
                {
                        string defaultName;
                        if (defaultNumberID > 99) {
-                               defaultName = "_ctrl" + defaultNumberID++;
+                               defaultName = "_ctl" + defaultNumberID++;
                        } else {
                                defaultName = defaultNameArray [defaultNumberID++];
                        }
                        return defaultName;
                }
 
-               void NullifyUniqueID ()\r
-               {\r
-                       uniqueID = null;\r
-                       if (!HasControls ())\r
-                               return;\r
-\r
-                       foreach (Control c in Controls)
+               void NullifyUniqueID ()
+               {
+                       uniqueID = null;
+                       if (!HasControls ())
+                               return;
+
+                       foreach (Control c in _controls)
                                c.NullifyUniqueID ();
                }
 
-               protected internal virtual void AddedControl (Control control, int index)\r
-               {\r
+               protected internal virtual void AddedControl (Control control, int index)
+               {
                        /* Ensure the control don't have more than 1 parent */
                        if (control._parent != null)
                                control._parent.Controls.Remove (control);
@@ -439,7 +567,7 @@ namespace System.Web.UI
                        if (nc != null) {
                                control._namingContainer = nc;
                                if (control.AutoID == true && control._userId == null)
-                                       control._userId =  nc.GetDefaultName () + "a";
+                                       control._userId =  nc.GetDefaultName ();
                        }
 
                        if ((stateMask & (INITING | INITED)) != 0)
@@ -465,54 +593,105 @@ namespace System.Web.UI
                                control.PreRenderRecursiveInternal ();
                }
 
-                protected virtual void AddParsedSubObject(object obj) //DIT\r
-                {\r
-                       WebTrace.PushContext ("Control.AddParsedSubobject ()");\r
-                        Control c = obj as Control;\r
-                       WebTrace.WriteLine ("Start: {0} -> {1}", obj, (c != null) ? c.ID : String.Empty);\r
-                        if (c != null) Controls.Add(c);\r
-                       WebTrace.WriteLine ("End");\r
-                       WebTrace.PopContext ();\r
-                }\r
-
-                protected void BuildProfileTree(string parentId, bool calcViewState)\r
-                {\r
-                        //TODO\r
-                }\r
+                protected virtual void AddParsedSubObject(object obj) //DIT
+                {
+                        Control c = obj as Control;
+                        if (c != null) Controls.Add(c);
+                }
+
+#if NET_2_0
+               [MonoTODO]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public virtual void ApplyStyleSheetSkin (Page page)
+               {
+                       if (!EnableTheming) /* this enough? */
+                               return;
+
+                       /* apply the style sheet skin here */
+                       if (page.StyleSheetPageTheme != null) {
+                               ControlSkin cs = page.StyleSheetPageTheme.GetControlSkin (GetType(), SkinID);
+                               if (cs != null)
+                                       cs.ApplySkin (this);
+                       }
+               }
+#endif         
+
+                protected void BuildProfileTree(string parentId, bool calcViewState)
+                {
+                        //TODO
+                }
+
+#if NET_2_0
+               protected void ClearChildControlState ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+               protected void ClearChildState ()
+               {
+                       throw new NotImplementedException ();
+               }
+#endif         
 
                 protected void ClearChildViewState ()
                 {
                        pendingVS = null;
                 }
 
-                protected virtual void CreateChildControls() {} //DIT\r
-                protected virtual ControlCollection CreateControlCollection() //DIT\r
-                {\r
-                        return new ControlCollection(this);\r
-                }\r
-\r
+#if NET_2_0
+                protected internal
+#else
+               protected
+#endif         
+               virtual void CreateChildControls() {} //DIT
+               
+                protected virtual ControlCollection CreateControlCollection() //DIT
+                {
+                        return new ControlCollection(this);
+                }
+
                 protected virtual void EnsureChildControls ()
                 {
                         if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
                                stateMask |= CREATING_CONTROLS;
-                                CreateChildControls();
+#if NET_2_0
+                               if (Adapter != null)
+                                       Adapter.CreateChildControls ();
+                               else
+#endif
+                                       CreateChildControls();
                                 ChildControlsCreated = true;
                                stateMask &= ~CREATING_CONTROLS;
                         }
                 }
 
+#if NET_2_0
+               protected void EnsureID ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+               protected bool HasEvents ()
+               {
+                       throw new NotImplementedException ();
+               }
+               
+#endif
+               
+
                protected bool IsLiteralContent()
                {
-                       if (HasControls () && Controls.Count == 1 && (Controls [0] is LiteralControl))
+                       if (HasControls () && _controls.Count == 1 && (_controls [0] is LiteralControl))
                                return true;
 
                        return false;
                }
 
-                public virtual Control FindControl (string id)\r
-                {\r
-                       return FindControl (id, 0);\r
-                }\r
+               [WebSysDescription ("")]
+                public virtual Control FindControl (string id)
+                {
+                       return FindControl (id, 0);
+                }
 
                Control LookForControlByName (string id)
                {
@@ -520,7 +699,7 @@ namespace System.Web.UI
                                return null;
 
                        Control result = null;
-                       foreach (Control c in Controls) {
+                       foreach (Control c in _controls) {
                                if (String.Compare (id, c._userId, true) == 0) {
                                        if (result != null && result != c) {
                                                throw new HttpException ("1 Found more than one control with ID '" + id + "'");
@@ -544,31 +723,31 @@ namespace System.Web.UI
                        return result;
                }
 
-                protected virtual Control FindControl (string id, int pathOffset)\r
-                {\r
-                       EnsureChildControls ();\r
-                       Control namingContainer = null;\r
+                protected virtual Control FindControl (string id, int pathOffset)
+                {
+                       EnsureChildControls ();
+                       Control namingContainer = null;
                        if ((stateMask & IS_NAMING_CONTAINER) == 0) {
-                               namingContainer = NamingContainer;\r
-                               if (namingContainer == null)\r
-                                       return null;\r
-\r
-                               return namingContainer.FindControl (id, pathOffset);\r
-                       }\r
+                               namingContainer = NamingContainer;
+                               if (namingContainer == null)
+                                       return null;
+
+                               return namingContainer.FindControl (id, pathOffset);
+                       }
 
                        if (!HasControls ())
                                return null;
 
-                       int colon = id.IndexOf (':', pathOffset);\r
-                       if (colon == -1)\r
-                               return LookForControlByName (id.Substring (pathOffset));\r
-                       \r
-                       string idfound = id.Substring (pathOffset, colon - pathOffset);\r
-                       namingContainer = LookForControlByName (idfound);\r
-                       if (namingContainer == null)\r
-                               return null;\r
-\r
-                       return namingContainer.FindControl (id, colon + 1);\r
+                       int colon = id.IndexOf (':', pathOffset);
+                       if (colon == -1)
+                               return LookForControlByName (id.Substring (pathOffset));
+                       
+                       string idfound = id.Substring (pathOffset, colon - pathOffset);
+                       namingContainer = LookForControlByName (idfound);
+                       if (namingContainer == null)
+                               return null;
+
+                       return namingContainer.FindControl (id, colon + 1);
                 }
 
                 protected virtual void LoadViewState(object savedState)
@@ -583,86 +762,210 @@ namespace System.Web.UI
                        }
                 }
 
-               [MonoTODO("Secure?")]\r
-                protected string MapPathSecure(string virtualPath)\r
-                {\r
-                       string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);\r
-                       return Context.Request.MapPath (combined);\r
-                }\r
-\r
-                protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT\r
-                {\r
-                        return false;\r
-                }\r
-                protected virtual void OnDataBinding(EventArgs e) //DIT\r
-                {\r
-                        if (_events != null)\r
-                        {\r
-                                EventHandler eh = (EventHandler)(_events[DataBindingEvent]);\r
-                                if (eh != null) eh(this, e);\r
-                        }\r
-                }\r
-                protected virtual void OnInit(EventArgs e) //DIT\r
-                {\r
-                        if (_events != null)\r
-                        {\r
-                                EventHandler eh = (EventHandler)(_events[InitEvent]);\r
-                                if (eh != null) eh(this, e);\r
-                        }\r
-                }\r
-                protected virtual void OnLoad(EventArgs e) //DIT\r
-                {\r
-                        if (_events != null)\r
-                        {\r
-                                EventHandler eh = (EventHandler)(_events[LoadEvent]);\r
-                                if (eh != null) eh(this, e);\r
-                        }\r
-                }\r
-                protected virtual void OnPreRender(EventArgs e) //DIT\r
-                {\r
-                        if (_events != null)\r
-                        {\r
-                                EventHandler eh = (EventHandler)(_events[PreRenderEvent]);\r
-                                if (eh != null) eh(this, e);\r
-                        }\r
-                }\r
-                protected virtual void OnUnload(EventArgs e) //DIT\r
-                {\r
-                        if (_events != null)\r
-                        {\r
-                                EventHandler eh = (EventHandler)(_events[UnloadEvent]);\r
-                                if (eh != null) eh(this, e);\r
-                        }\r
-                }\r
-                \r
-                protected void RaiseBubbleEvent(object source, EventArgs args)\r
-                {\r
-                       Control c = Parent;\r
-                       while (c != null) {\r
-                               if (c.OnBubbleEvent (source, args))\r
-                                       break;\r
-                               c = c.Parent;\r
-                       }\r
-                }\r
-\r
-                protected virtual void Render(HtmlTextWriter writer) //DIT\r
-                {\r
-                        RenderChildren(writer);\r
-                }\r
-
-                protected virtual void RenderChildren (HtmlTextWriter writer) //DIT
+               [MonoTODO("Secure?")]
+                protected string MapPathSecure(string virtualPath)
+                {
+                       string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
+                       return Context.Request.MapPath (combined);
+                }
+
+                protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
+                {
+#if MONO_TRACE
+                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                       string type_name = null;
+                       if (trace != null) {
+                               type_name = GetType ().Name;
+                               trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
+                       }
+#endif
+                        return false;
+                }
+
+                protected virtual void OnDataBinding (EventArgs e)
+                {
+                       if ((event_mask & databinding_mask) != 0) {
+                                EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
+                                if (eh != null) {
+#if MONO_TRACE
+                                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                                       string type_name = null;
+                                       if (trace != null) {
+                                               type_name = GetType ().Name;
+                                               trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
+                                       }
+#endif
+                                       eh (this, e);
+                               }
+                        }
+                }
+
+#if NET_2_0
+               protected internal
+#else          
+                protected
+#endif         
+               virtual void OnInit (EventArgs e)
+                {
+                       if ((event_mask & init_mask) != 0) {
+                                EventHandler eh = (EventHandler)(_events [InitEvent]);
+                                if (eh != null) {
+#if MONO_TRACE
+                                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                                       string type_name = null;
+                                       if (trace != null) {
+                                               type_name = GetType ().Name;
+                                               trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
+                                       }
+#endif
+                                       eh (this, e);
+                               }
+                        }
+                }
+
+#if NET_2_0
+               protected internal
+#else
+               protected
+#endif         
+               virtual void OnLoad (EventArgs e)
+                {
+                       if ((event_mask & load_mask) != 0) {
+                                EventHandler eh = (EventHandler)(_events [LoadEvent]);
+                                if (eh != null) {
+#if MONO_TRACE
+                                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                                       string type_name = null;
+                                       if (trace != null) {
+                                               type_name = GetType ().Name;
+                                               trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
+                                       }
+#endif
+                                       eh (this, e);
+                               }
+                        }
+                }
+
+#if NET_2_0
+               protected internal
+#else
+               protected
+#endif
+                virtual void OnPreRender (EventArgs e)
+                {
+                       if ((event_mask & prerender_mask) != 0) {
+                                EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
+                                if (eh != null) {
+#if MONO_TRACE
+                                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                                       string type_name = null;
+                                       if (trace != null) {
+                                               type_name = GetType ().Name;
+                                               trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
+                                       }
+#endif
+                                       eh (this, e);
+                               }
+                        }
+                }
+
+#if NET_2_0
+               protected internal
+#else
+               protected
+#endif
+                virtual void OnUnload(EventArgs e)
+                {
+                       if ((event_mask & unload_mask) != 0) {
+                                EventHandler eh = (EventHandler)(_events [UnloadEvent]);
+                                if (eh != null) {
+#if MONO_TRACE
+                                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                                       string type_name = null;
+                                       if (trace != null) {
+                                               type_name = GetType ().Name;
+                                               trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
+                                       }
+#endif
+                                       eh (this, e);
+                               }
+                        }
+                }
+
+#if NET_2_0
+               protected internal Stream OpenFile (string path)
+               {
+                       throw new NotImplementedException ();
+               }
+#endif         
+
+                protected void RaiseBubbleEvent(object source, EventArgs args)
+                {
+                       Control c = Parent;
+                       while (c != null) {
+#if MONO_TRACE
+                               TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                               string type_name = null;
+                               if (trace != null) {
+                                       type_name = GetType ().Name;
+                                       trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
+                               }
+#endif
+                               if (c.OnBubbleEvent (source, args)) {
+#if MONO_TRACE
+                                       if (trace != null)
+                                               trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
+#endif
+                                       break;
+                               }
+#if MONO_TRACE
+                               if (trace != null)
+                                       trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
+#endif
+                               c = c.Parent;
+                       }
+                }
+
+#if NET_2_0
+               protected internal
+#else
+               protected
+#endif
+                virtual void Render(HtmlTextWriter writer) //DIT
+                {
+                       RenderChildren(writer);
+                }
+
+#if NET_2_0
+               protected internal
+#else
+               protected
+#endif
+                virtual void RenderChildren (HtmlTextWriter writer) //DIT
                 {
                         if (_renderMethodDelegate != null) {
                                 _renderMethodDelegate (writer, this);
-                       } else if (HasControls ()) {
-                               int len = Controls.Count;
+                       } else if (_controls != null) {
+                               int len = _controls.Count;
                                for (int i = 0; i < len; i++) {
-                                       Control c = Controls [i];
-                                       c.RenderControl (writer);
+                                       Control c = _controls [i];
+#if NET_2_0
+                                       if (c.Adapter != null)
+                                               c.RenderControl (writer, c.Adapter);
+                                       else
+#endif
+                                               c.RenderControl (writer);
                                }
                        }
                 }
 
+#if NET_2_0
+               protected virtual ControlAdapter ResolveAdapter ()
+               {
+                       throw new NotImplementedException ();
+               }
+#endif         
+
                 protected virtual object SaveViewState ()
                 {
                        if ((stateMask & VISIBLE_CHANGED) != 0) {
@@ -674,104 +977,78 @@ namespace System.Web.UI
                        return _viewState.SaveViewState ();
                 }
 
-                protected virtual void TrackViewState()\r
-                {\r
-                       if (_viewState != null)\r
-                               _viewState.TrackViewState ();\r
+                protected virtual void TrackViewState()
+                {
+                       if (_viewState != null)
+                               _viewState.TrackViewState ();
 
                         stateMask |= TRACK_VIEWSTATE;
-                }\r
-                \r
-                public virtual void Dispose()\r
-                {\r
-                        if (_events != null)\r
-                        {\r
-                                EventHandler eh = (EventHandler) _events [DisposedEvent];\r
-                                if (eh != null)\r
-                                       eh(this, EventArgs.Empty);\r
-                        }\r
-                }\r
+                }
+
+                public virtual void Dispose ()
+                {
+                       if ((event_mask & disposed_mask) != 0) {
+                                EventHandler eh = (EventHandler)(_events [DisposedEvent]);
+                                if (eh != null) eh (this, EventArgs.Empty);
+                        }
+                }
 
                [WebCategory ("FIXME")]
-               [WebSysDescription ("Raised when the contols databound properties are evaluated.")]\r
-                public event EventHandler DataBinding //DIT\r
-                {\r
-                        add\r
-                        {\r
-                                Events.AddHandler(DataBindingEvent, value);\r
-                        }\r
-                        remove\r
-                        {\r
-                                Events.RemoveHandler(DataBindingEvent, value);\r
-                        }\r
+               [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
+                public event EventHandler DataBinding {
+                        add {
+                               event_mask |= databinding_mask;
+                                Events.AddHandler (DataBindingEvent, value);
+                        }
+                        remove { Events.RemoveHandler (DataBindingEvent, value); }
+                }
+
+               [WebSysDescription ("Raised when the contol is disposed.")]
+                public event EventHandler Disposed {
+                        add {
+                               event_mask |= disposed_mask;
+                                Events.AddHandler (DisposedEvent, value);
+                        }
+                        remove { Events.RemoveHandler (DisposedEvent, value); }
                 }
 
-               [WebSysDescription ("Raised when the contol is disposed.")]\r
-                public event EventHandler Disposed //DIT\r
-                {\r
-                        add\r
-                        {\r
-                                Events.AddHandler(DisposedEvent, value);\r
-                        }\r
-                        remove\r
-                        {\r
-                                Events.RemoveHandler(DisposedEvent, value);\r
-                        }\r
+               [WebSysDescription ("Raised when the page containing the control is initialized.")]
+                public event EventHandler Init {
+                        add {
+                               event_mask |= init_mask;
+                                Events.AddHandler (InitEvent, value);
+                        }
+                        remove { Events.RemoveHandler (InitEvent, value); }
                 }
 
-               [WebSysDescription ("Raised when the page containing the control is initialized.")]\r
-                public event EventHandler Init //DIT\r
-                {\r
-                        add\r
-                        {\r
-                                Events.AddHandler(InitEvent, value);\r
-                        }\r
-                        remove\r
-                        {\r
-                                Events.RemoveHandler(InitEvent, value);\r
-                        }\r
+               [WebSysDescription ("Raised after the page containing the control has been loaded.")]
+                public event EventHandler Load {
+                        add {
+                               event_mask |= load_mask;
+                                Events.AddHandler (LoadEvent, value);
+                        }
+                        remove { Events.RemoveHandler (LoadEvent, value); }
                 }
 
-               [WebSysDescription ("Raised after the page containing the control has been loaded.")]\r
-                public event EventHandler Load //DIT\r
-                {\r
-                        add\r
-                        {\r
-                                Events.AddHandler(LoadEvent, value);\r
-                        }\r
-                        remove\r
-                        {\r
-                                Events.RemoveHandler(LoadEvent, value);\r
-                        }\r
+               [WebSysDescription ("Raised before the page containing the control is rendered.")]
+                public event EventHandler PreRender {
+                        add {
+                               event_mask |= prerender_mask;
+                                Events.AddHandler (PreRenderEvent, value);
+                        }
+                        remove { Events.RemoveHandler (PreRenderEvent, value); }
                 }
 
-               [WebSysDescription ("Raised before the page containing the control is rendered.")]\r
-                public event EventHandler PreRender //DIT\r
-                {\r
-                        add\r
-                        {\r
-                                Events.AddHandler(PreRenderEvent, value);\r
-                        }\r
-                        remove\r
-                        {\r
-                                Events.RemoveHandler(PreRenderEvent, value);\r
-                        }\r
+               [WebSysDescription ("Raised when the page containing the control is unloaded.")]
+                public event EventHandler Unload {
+                        add {
+                               event_mask |= unload_mask;
+                                Events.AddHandler (UnloadEvent, value);
+                        }
+                        remove { Events.RemoveHandler (UnloadEvent, value); }
                 }
 
-               [WebSysDescription ("Raised when the page containing the control is unloaded.")]\r
-                public event EventHandler Unload //DIT\r
-                {\r
-                        add\r
-                        {\r
-                                Events.AddHandler(UnloadEvent, value);\r
-                        }\r
-                        remove\r
-                        {\r
-                                Events.RemoveHandler(UnloadEvent, value);\r
-                        }\r
-                }\r
-\r
-               public virtual void DataBind() //DIT\r
+               public virtual void DataBind() //DIT
                {
                        #if NET_2_0
                        DataBind (true);
@@ -790,9 +1067,9 @@ namespace System.Web.UI
                        if (!HasControls ())
                                return;
                        
-                       int len = Controls.Count;
+                       int len = _controls.Count;
                        for (int i = 0; i < len; i++) {
-                               Control c = Controls [i];
+                               Control c = _controls [i];
                                c.DataBind ();
                        }
                }
@@ -810,9 +1087,32 @@ namespace System.Web.UI
 #endif
                void RenderControl (HtmlTextWriter writer)
                {
-                   if ((stateMask & VISIBLE) != 0)
-                           Render(writer);
+                       if ((stateMask & VISIBLE) != 0) {
+                               HttpContext ctx = Context;
+                               TraceContext trace = (ctx != null) ? ctx.Trace : null;
+                               int pos = 0;
+                               if ((trace != null) && trace.IsEnabled)
+                                       pos = ctx.Response.GetOutputByteCount ();
+
+                               Render(writer);
+                               if ((trace != null) && trace.IsEnabled) {
+                                       int size = ctx.Response.GetOutputByteCount () - pos;
+                                       trace.SaveSize (this, size >= 0 ? size : 0);
+                               }
+                       }
+               }
+
+#if NET_2_0
+               protected void RenderControl (HtmlTextWriter writer,
+                                             ControlAdapter adapter)
+               {
+                       if ((stateMask & VISIBLE) != 0) {
+                               adapter.BeginRender (writer);
+                               adapter.Render (writer);
+                               adapter.EndRender (writer);
+                       }
                }
+#endif         
 
                public string ResolveUrl (string relativeUrl)
                {
@@ -837,111 +1137,191 @@ namespace System.Web.UI
                        return _renderMethodDelegate != null;
                }
 
-               [EditorBrowsable (EditorBrowsableState.Advanced)]\r
-                public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT\r
-                {\r
-                        _renderMethodDelegate = renderMethod;\r
-                }\r
-\r
-                internal void LoadRecursive()\r
-                {\r
-                        OnLoad (EventArgs.Empty);\r
-                        if (HasControls ()) {\r
-                               int len = Controls.Count;
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+                public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
+                {
+                        _renderMethodDelegate = renderMethod;
+                }
+
+                internal void LoadRecursive()
+                {
+#if MONO_TRACE
+                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                       string type_name = null;
+                       if (trace != null) {
+                               type_name = GetType ().Name;
+                               trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
+                       }
+#endif
+#if NET_2_0
+                       if (Adapter != null)
+                               Adapter.OnLoad (EventArgs.Empty);
+                       else
+#endif
+                               OnLoad (EventArgs.Empty);
+                        if (HasControls ()) {
+                               int len = _controls.Count;
                                for (int i=0;i<len;i++)
-                               {\r
-                                       Control c = Controls[i];\r
-                                       c.LoadRecursive ();\r
-                               }\r
-                       }\r
+                               {
+                                       Control c = _controls[i];
+                                       c.LoadRecursive ();
+                               }
+                       }
+
+#if MONO_TRACE
+                       if (trace != null)
+                               trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
+#endif
                        stateMask |= LOADED;
-                }\r
-\r
-                internal void UnloadRecursive(Boolean dispose)\r
-                {\r
-                       if (HasControls ()) {\r
-                               int len = Controls.Count;
+                }
+
+                internal void UnloadRecursive(Boolean dispose)
+                {
+#if MONO_TRACE
+                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                       string type_name = null;
+                       if (trace != null) {
+                               type_name = GetType ().Name;
+                               trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
+                       }
+#endif
+                       if (HasControls ()) {
+                               int len = _controls.Count;
                                for (int i=0;i<len;i++)
-                               {\r
-                                       Control c = Controls[i];                                        \r
-                                       c.UnloadRecursive (dispose);\r
+                               {
+                                       Control c = _controls[i];                                       
+                                       c.UnloadRecursive (dispose);
                                }
-                       }\r
-\r
-                        OnUnload (EventArgs.Empty);\r
-                        if (dispose)\r
-                               Dispose();\r
-                }\r
+                       }
+
+#if MONO_TRACE
+                       if (trace != null)
+                               trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
+#endif
+#if NET_2_0
+                       if (Adapter != null)
+                               Adapter.OnUnload (EventArgs.Empty);
+                       else
+#endif
+                               OnUnload (EventArgs.Empty);
+                        if (dispose)
+                               Dispose();
+                }
 
                 internal void PreRenderRecursiveInternal()
                 {
                        if ((stateMask & VISIBLE) != 0) {
                                EnsureChildControls ();
-                               OnPreRender (EventArgs.Empty);
+#if MONO_TRACE
+                               TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                               string type_name = null;
+                               if (trace != null) {
+                                       type_name = GetType ().Name;
+                                       trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
+                               }
+#endif
+#if NET_2_0
+                               if (Adapter != null)
+                                       Adapter.OnPreRender (EventArgs.Empty);
+                               else
+#endif
+                                       OnPreRender (EventArgs.Empty);
                                if (!HasControls ())
                                        return;
                                
-                               int len = Controls.Count;
+                               int len = _controls.Count;
                                for (int i=0;i<len;i++)
-                               {\r
-                                       Control c = Controls[i];
+                               {
+                                       Control c = _controls[i];
                                        c.PreRenderRecursiveInternal ();
                                }
+#if MONO_TRACE
+                               if (trace != null)
+                                       trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
+#endif
                        }
                        stateMask |= PRERENDERED;
                 }
 
-                internal void InitRecursive(Control namingContainer)\r
-                {\r
-                        if (HasControls ()) {\r
+                internal void InitRecursive(Control namingContainer)
+                {
+#if MONO_TRACE
+                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                       string type_name = null;
+                       if (trace != null) {
+                               type_name = GetType ().Name;
+                               trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
+                       }
+#endif
+                        if (HasControls ()) {
                                if ((stateMask & IS_NAMING_CONTAINER) != 0)
-                                       namingContainer = this;\r
-\r
-                               if (namingContainer != null && \r
-                                   namingContainer._userId == null &&\r
-                                   namingContainer.AutoID)\r
-                                       namingContainer._userId = namingContainer.GetDefaultName () + "b";\r
-\r
-                               int len = Controls.Count;
+                                       namingContainer = this;
+
+                               if (namingContainer != null && 
+                                   namingContainer._userId == null &&
+                                   namingContainer.AutoID)
+                                       namingContainer._userId = namingContainer.GetDefaultName () + "b";
+
+                               int len = _controls.Count;
                                for (int i=0;i<len;i++)
-                               {\r
-                                       Control c = Controls[i];\r
-                                       c._page = Page;\r
-                                       c._namingContainer = namingContainer;\r
-                                       if (namingContainer != null && c._userId == null && c.AutoID)\r
-                                               c._userId = namingContainer.GetDefaultName () + "c";\r
-                                       c.InitRecursive (namingContainer);      \r
+                               {
+                                       Control c = _controls[i];
+                                       c._page = Page;
+                                       c._namingContainer = namingContainer;
+                                       if (namingContainer != null && c._userId == null && c.AutoID)
+                                               c._userId = namingContainer.GetDefaultName () + "c";
+                                       c.InitRecursive (namingContainer);      
                                }
-                       }\r
-\r
+                       }
+
                        stateMask |= INITING;
-                        OnInit (EventArgs.Empty);\r
-                       TrackViewState ();\r
+#if NET_2_0
+                       ApplyTheme ();
+                       
+                       if (Adapter != null)
+                               Adapter.OnInit (EventArgs.Empty);
+                       else
+#endif
+                               OnInit (EventArgs.Empty);
+#if MONO_TRACE
+                       if (trace != null)
+                               trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
+#endif
+                       TrackViewState ();
                        stateMask |= INITED;
                        stateMask &= ~INITING;
-                }\r
+                }
 
                 internal object SaveViewStateRecursive ()
                 {
                        if (!EnableViewState)
                                return null;
 
+#if MONO_TRACE
+                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                       string type_name = null;
+                       if (trace != null) {
+                               type_name = GetType ().Name;
+                               trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
+                       }
+#endif
+
                        ArrayList controlList = null;
                        ArrayList controlStates = null;
 
                        int idx = -1;
                        if (HasControls ())
                        {
-                               int len = Controls.Count;
+                               int len = _controls.Count;
                                for (int i=0;i<len;i++)
                                {
-                                       Control ctrl = Controls[i];
+                                       Control ctrl = _controls[i];
                                        object ctrlState = ctrl.SaveViewStateRecursive ();
                                        idx++;
                                        if (ctrlState == null)
                                                continue;
 
-                                       if (controlList == null) \r
+                                       if (controlList == null) 
                                        {
                                                controlList = new ArrayList ();
                                                controlStates = new ArrayList ();
@@ -953,9 +1333,22 @@ namespace System.Web.UI
                        }
 
                        object thisState = SaveViewState ();
-                       if (thisState == null && controlList == null && controlStates == null)
+                       if (thisState == null && controlList == null && controlStates == null) {
+#if MONO_TRACE
+                               if (trace != null) {
+                                       trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
+                                       trace.SaveViewState (this, null);
+                               }
+#endif
                                return null;
+                       }
 
+#if MONO_TRACE
+                       if (trace != null) {
+                               trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
+                               trace.SaveViewState (this, thisState);
+                       }
+#endif
                        return new Triplet (thisState, controlList, controlStates);
                 }
                 
@@ -964,6 +1357,14 @@ namespace System.Web.UI
                        if (!EnableViewState || savedState == null)
                                return;
 
+#if MONO_TRACE
+                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                       string type_name = null;
+                       if (trace != null) {
+                               type_name = GetType ().Name;
+                               trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
+                       }
+#endif
                        Triplet savedInfo = (Triplet) savedState;
                        LoadViewState (savedInfo.First);
 
@@ -985,32 +1386,39 @@ namespace System.Web.UI
                                }
                        }
 
+#if MONO_TRACE
+                       if (trace != null)
+                               trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
+#endif
                        stateMask |= VIEWSTATE_LOADED;
                 }
+
+#if NET_2_0
+               internal ControlSkin controlSkin;
+
+                internal void ApplyTheme ()
+                {
+#if MONO_TRACE
+                       TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
+                       string type_name = null;
+                       if (trace != null) {
+                               type_name = GetType ().Name;
+                               trace.Write ("control", String.Format ("ApplyThemeRecursive {0} {1}", _userId, type_name));
+                       }
+#endif
+                       if (Page.PageTheme != null) {
+                               ControlSkin controlSkin = Page.PageTheme.GetControlSkin (GetType (), SkinID);
+                               if (controlSkin != null)
+                                       controlSkin.ApplySkin (this);
+                       }
+
+#if MONO_TRACE
+                       if (trace != null)
+                               trace.Write ("control", String.Format ("End ApplyThemeRecursive {0} {1}", _userId, type_name));
+#endif
+                }
+#endif
                 
-                void IParserAccessor.AddParsedSubObject(object obj)\r
-                {\r
-                       AddParsedSubObject(obj);\r
-                }\r
-                \r
-                DataBindingCollection IDataBindingsAccessor.DataBindings\r
-                {\r
-                       get\r
-                       {\r
-                               if(dataBindings == null)\r
-                                       dataBindings = new DataBindingCollection();\r
-                               return dataBindings;\r
-                       }\r
-                }\r
-                \r
-                bool IDataBindingsAccessor.HasDataBindings\r
-                {\r
-                       get\r
-                       {\r
-                               return (dataBindings!=null && dataBindings.Count>0);\r
-                       }\r
-                }\r
                internal bool AutoID
                {
                        get { return (stateMask & AUTOID) != 0; }
@@ -1022,41 +1430,38 @@ namespace System.Web.UI
                        }
                }
 
-                internal void PreventAutoID()\r
-                {\r
-                       AutoID = false;\r
-                }\r
-                \r
-               protected internal virtual void RemovedControl (Control control)\r
-               {\r
-                       control.UnloadRecursive (false);\r
-                       control._parent = null;\r
-                       control._page = null;\r
-                       control._namingContainer = null;\r
-               }\r
-\r
+               protected internal virtual void RemovedControl (Control control)
+               {
+                       control.UnloadRecursive (false);
+                       control._parent = null;
+                       control._page = null;
+                       control._namingContainer = null;
+               }
+
+
 #if NET_2_0
 
                string skinId = string.Empty;
                
+               [Browsable (false)]
+               [Themeable (false)]
+               [DefaultValue (true)]
                public virtual bool EnableTheming
                {
                        get { return (stateMask & ENABLE_THEMING) != 0; }
                        set { SetMask (ENABLE_THEMING, value); }
                }
                
+               [Browsable (false)]
+               [DefaultValue ("")]
+               [Filterable (false)]
                public virtual string SkinID
                {
                        get { return skinId; }
                        set { skinId = value; }
                }
                
-               protected string GetWebResourceUrl (string resourceName)
-               {
-                       return Page.ClientScript.GetWebResourceUrl (GetType(), resourceName); 
-               } 
-
-               string IUrlResolutionService.ResolveClientUrl (string url)
+               public string ResolveClientUrl (string url)
                {
                        throw new NotImplementedException ();               
                }
@@ -1069,12 +1474,12 @@ namespace System.Web.UI
                {
                        throw new NotImplementedException ();               
                }
-       
+
                void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
                {
-                       throw new NotImplementedException ();               
+                       SetDesignModeState (designData);
                }
-
+       
                void IControlDesignerAccessor.SetOwnerControl (Control control)
                {
                        throw new NotImplementedException ();               
@@ -1089,21 +1494,21 @@ namespace System.Web.UI
                ExpressionBindingCollection IExpressionsAccessor.Expressions { 
                        get { 
                                if (expressionBindings == null)
-                                       expressionBindings = new ExpressionBindingCollection ();\r
-                               return expressionBindings;\r
+                                       expressionBindings = new ExpressionBindingCollection ();
+                               return expressionBindings;
                        } 
                }
                
                bool IExpressionsAccessor.HasExpressions { 
-                       get {\r
-                               return (expressionBindings != null && expressionBindings.Count > 0);\r
-                       }\r
+                       get {
+                               return (expressionBindings != null && expressionBindings.Count > 0);
+                       }
                }
 
                [MonoTODO]
-               public virtual void Focus()\r
-               {\r
-                       throw new NotImplementedException();\r
+               public virtual void Focus()
+               {
+                       throw new NotImplementedException();
                }
                
                protected internal virtual void LoadControlState (object state)
@@ -1137,7 +1542,36 @@ namespace System.Web.UI
                        }
                }
                
+               protected virtual IDictionary GetDesignModeState ()
+               {
+                       throw new NotImplementedException ();               
+               }
                
-#endif\r
-        }\r
-}\r
+               protected virtual void SetDesignModeState (IDictionary data)
+               {
+                       throw new NotImplementedException ();               
+               }
+#endif
+               void IParserAccessor.AddParsedSubObject (object obj) {
+                       this.AddParsedSubObject (obj);
+               }
+
+               DataBindingCollection IDataBindingsAccessor.DataBindings {
+                       get {
+                               if (dataBindings == null) {
+                                       dataBindings = new DataBindingCollection ();
+                               }
+                               return dataBindings;
+                       }
+               }
+
+               bool IDataBindingsAccessor.HasDataBindings {
+                       get {
+                               if (dataBindings != null && dataBindings.Count > 0) {
+                                       return true;
+                               }
+                               return false;
+                       }
+               }
+        }
+}