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