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