* support-test-*.cs: Rename from test-*-p2.cs.
[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                                         if (_controls != null)
442                                                 _controls.Clear();
443                                 }
444
445                                 SetMask (CHILD_CONTROLS_CREATED, value);
446                         }
447                 }
448
449                 [Browsable (false)]
450                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
451                 protected virtual HttpContext Context //DIT
452                 {
453                         get
454                         {
455                                 HttpContext context;
456                                 if (_context != null)
457                                         return _context;
458                                 if (_parent == null)
459                                         return HttpContext.Current;
460                                 context = _parent.Context;
461                                 if (context != null)
462                                         return context;
463                                 return HttpContext.Current;
464                         }
465                 }
466
467                 protected EventHandlerList Events {
468                         get {
469                                 if (_events == null)
470                                         _events = new EventHandlerList ();
471                                 return _events;
472                         }
473                 }
474
475                 protected bool HasChildViewState {
476                         get {
477                                 return (pendingVS != null && pendingVS.Count > 0);
478                         }
479                 }
480
481                 protected bool IsTrackingViewState {
482                         get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
483                 }
484
485                 [Browsable (false)]
486                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
487                 [WebSysDescription ("ViewState")]
488                 protected virtual StateBag ViewState
489                 {
490                         get
491                         {
492                                 if(_viewState == null)
493                                         _viewState = new StateBag (ViewStateIgnoresCase);
494
495                                 if (IsTrackingViewState)
496                                         _viewState.TrackViewState ();
497
498                                 return _viewState;
499                         }
500                 }
501
502                 [Browsable (false)]
503                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
504                 protected virtual bool ViewStateIgnoresCase
505                 {
506                         get {
507                                 return false;
508                         }
509                 }
510
511                 internal bool AutoEventWireup {
512                         get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
513                         set { SetMask (AUTO_EVENT_WIREUP, value); }
514                 }
515
516                 internal void SetBindingContainer (bool isBC)
517                 {
518                         SetMask (BINDING_CONTAINER, isBC);
519                 }
520
521                 internal void ResetChildNames ()
522                 {
523                         defaultNumberID = 0;
524                 }
525
526                 string GetDefaultName ()
527                 {
528                         string defaultName;
529                         if (defaultNumberID > 99) {
530                                 defaultName = "_ctl" + defaultNumberID++;
531                         } else {
532                                 defaultName = defaultNameArray [defaultNumberID++];
533                         }
534                         return defaultName;
535                 }
536
537                 void NullifyUniqueID ()
538                 {
539                         uniqueID = null;
540                         if (!HasControls ())
541                                 return;
542
543                         foreach (Control c in _controls)
544                                 c.NullifyUniqueID ();
545                 }
546
547                 protected internal virtual void AddedControl (Control control, int index)
548                 {
549                         /* Ensure the control don't have more than 1 parent */
550                         if (control._parent != null)
551                                 control._parent.Controls.Remove (control);
552
553                         control._parent = this;
554                         control._page = _page;
555                         Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
556
557                         if (nc != null) {
558                                 control._namingContainer = nc;
559                                 if (control.AutoID == true && control._userId == null)
560                                         control._userId =  nc.GetDefaultName ();
561                         }
562
563                         if ((stateMask & (INITING | INITED)) != 0)
564                                 control.InitRecursive (nc);
565
566                         if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
567                                 if (pendingVS != null) {
568                                         object vs = pendingVS [index];
569                                         if (vs != null) {
570                                                 pendingVS.Remove (index);
571                                                 if (pendingVS.Count == 0)
572                                                         pendingVS = null;
573                                         
574                                                 control.LoadViewStateRecursive (vs);
575                                         }
576                                 }
577                         }
578
579                         if ((stateMask & LOADED) != 0)
580                                 control.LoadRecursive ();
581                         
582                         if ((stateMask & PRERENDERED) != 0)
583                                 control.PreRenderRecursiveInternal ();
584                 }
585
586                 protected virtual void AddParsedSubObject(object obj) //DIT
587                 {
588                         Control c = obj as Control;
589                         if (c != null) Controls.Add(c);
590                 }
591
592 #if NET_2_0
593                 [EditorBrowsable (EditorBrowsableState.Advanced)]
594                 public virtual void ApplyStyleSheetSkin (Page page)
595                 {
596                         throw new NotImplementedException ();
597                 }
598 #endif          
599
600                 protected void BuildProfileTree(string parentId, bool calcViewState)
601                 {
602                         //TODO
603                 }
604
605 #if NET_2_0
606                 protected void ClearChildControlState ()
607                 {
608                         throw new NotImplementedException ();
609                 }
610
611                 protected void ClearChildState ()
612                 {
613                         throw new NotImplementedException ();
614                 }
615 #endif          
616
617                 protected void ClearChildViewState ()
618                 {
619                         pendingVS = null;
620                 }
621
622 #if NET_2_0
623                 protected internal
624 #else
625                 protected
626 #endif          
627                 virtual void CreateChildControls() {} //DIT
628                 
629                 protected virtual ControlCollection CreateControlCollection() //DIT
630                 {
631                         return new ControlCollection(this);
632                 }
633
634                 protected virtual void EnsureChildControls ()
635                 {
636                         if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
637                                 stateMask |= CREATING_CONTROLS;
638 #if NET_2_0
639                                 if (Adapter != null)
640                                         Adapter.CreateChildControls ();
641                                 else
642 #endif
643                                         CreateChildControls();
644                                 ChildControlsCreated = true;
645                                 stateMask &= ~CREATING_CONTROLS;
646                         }
647                 }
648
649 #if NET_2_0
650                 protected void EnsureID ()
651                 {
652                         throw new NotImplementedException ();
653                 }
654
655                 protected bool HasEvents ()
656                 {
657                         throw new NotImplementedException ();
658                 }
659                 
660 #endif
661                 
662
663                 protected bool IsLiteralContent()
664                 {
665                         if (HasControls () && _controls.Count == 1 && (_controls [0] is LiteralControl))
666                                 return true;
667
668                         return false;
669                 }
670
671                 [WebSysDescription ("")]
672                 public virtual Control FindControl (string id)
673                 {
674                         return FindControl (id, 0);
675                 }
676
677                 Control LookForControlByName (string id)
678                 {
679                         if (!HasControls ())
680                                 return null;
681
682                         Control result = null;
683                         foreach (Control c in _controls) {
684                                 if (String.Compare (id, c._userId, true) == 0) {
685                                         if (result != null && result != c) {
686                                                 throw new HttpException ("1 Found more than one control with ID '" + id + "'");
687                                         }
688
689                                         result = c;
690                                         continue;
691                                 }
692
693                                 if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
694                                         Control child = c.LookForControlByName (id);
695                                         if (child != null) {
696                                                 if (result != null && result != child)
697                                                         throw new HttpException ("2 Found more than one control with ID '" + id + "'");
698
699                                                 result = child;
700                                         }
701                                 }
702                         }
703
704                         return result;
705                 }
706
707                 protected virtual Control FindControl (string id, int pathOffset)
708                 {
709                         EnsureChildControls ();
710                         Control namingContainer = null;
711                         if ((stateMask & IS_NAMING_CONTAINER) == 0) {
712                                 namingContainer = NamingContainer;
713                                 if (namingContainer == null)
714                                         return null;
715
716                                 return namingContainer.FindControl (id, pathOffset);
717                         }
718
719                         if (!HasControls ())
720                                 return null;
721
722                         int colon = id.IndexOf (':', pathOffset);
723                         if (colon == -1)
724                                 return LookForControlByName (id.Substring (pathOffset));
725                         
726                         string idfound = id.Substring (pathOffset, colon - pathOffset);
727                         namingContainer = LookForControlByName (idfound);
728                         if (namingContainer == null)
729                                 return null;
730
731                         return namingContainer.FindControl (id, colon + 1);
732                 }
733
734                 protected virtual void LoadViewState(object savedState)
735                 {
736                         if (savedState != null) {
737                                 ViewState.LoadViewState (savedState);
738                                 object o = ViewState ["Visible"];
739                                 if (o != null) {
740                                         SetMask (VISIBLE, (bool) o);
741                                         stateMask |= VISIBLE_CHANGED;
742                                 }
743                         }
744                 }
745
746                 [MonoTODO("Secure?")]
747                 protected string MapPathSecure(string virtualPath)
748                 {
749                         string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
750                         return Context.Request.MapPath (combined);
751                 }
752
753                 protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
754                 {
755 #if MONO_TRACE
756                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
757                         string type_name = null;
758                         if (trace != null) {
759                                 type_name = GetType ().Name;
760                                 trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
761                         }
762 #endif
763                         return false;
764                 }
765
766                 protected virtual void OnDataBinding (EventArgs e)
767                 {
768                         if ((event_mask & databinding_mask) != 0) {
769                                 EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
770                                 if (eh != null) {
771 #if MONO_TRACE
772                                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
773                                         string type_name = null;
774                                         if (trace != null) {
775                                                 type_name = GetType ().Name;
776                                                 trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
777                                         }
778 #endif
779                                         eh (this, e);
780                                 }
781                         }
782                 }
783
784 #if NET_2_0
785                 protected internal
786 #else           
787                 protected
788 #endif          
789                 virtual void OnInit (EventArgs e)
790                 {
791                         if ((event_mask & init_mask) != 0) {
792                                 EventHandler eh = (EventHandler)(_events [InitEvent]);
793                                 if (eh != null) {
794 #if MONO_TRACE
795                                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
796                                         string type_name = null;
797                                         if (trace != null) {
798                                                 type_name = GetType ().Name;
799                                                 trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
800                                         }
801 #endif
802                                         eh (this, e);
803                                 }
804                         }
805                 }
806
807 #if NET_2_0
808                 protected internal
809 #else
810                 protected
811 #endif          
812                 virtual void OnLoad (EventArgs e)
813                 {
814                         if ((event_mask & load_mask) != 0) {
815                                 EventHandler eh = (EventHandler)(_events [LoadEvent]);
816                                 if (eh != null) {
817 #if MONO_TRACE
818                                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
819                                         string type_name = null;
820                                         if (trace != null) {
821                                                 type_name = GetType ().Name;
822                                                 trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
823                                         }
824 #endif
825                                         eh (this, e);
826                                 }
827                         }
828                 }
829
830 #if NET_2_0
831                 protected internal
832 #else
833                 protected
834 #endif
835                 virtual void OnPreRender (EventArgs e)
836                 {
837                         if ((event_mask & prerender_mask) != 0) {
838                                 EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
839                                 if (eh != null) {
840 #if MONO_TRACE
841                                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
842                                         string type_name = null;
843                                         if (trace != null) {
844                                                 type_name = GetType ().Name;
845                                                 trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
846                                         }
847 #endif
848                                         eh (this, e);
849                                 }
850                         }
851                 }
852
853 #if NET_2_0
854                 protected internal
855 #else
856                 protected
857 #endif
858                 virtual void OnUnload(EventArgs e)
859                 {
860                         if ((event_mask & unload_mask) != 0) {
861                                 EventHandler eh = (EventHandler)(_events [UnloadEvent]);
862                                 if (eh != null) {
863 #if MONO_TRACE
864                                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
865                                         string type_name = null;
866                                         if (trace != null) {
867                                                 type_name = GetType ().Name;
868                                                 trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
869                                         }
870 #endif
871                                         eh (this, e);
872                                 }
873                         }
874                 }
875
876 #if NET_2_0
877                 protected internal Stream OpenFile (string path)
878                 {
879                         throw new NotImplementedException ();
880                 }
881 #endif          
882
883                 protected void RaiseBubbleEvent(object source, EventArgs args)
884                 {
885                         Control c = Parent;
886                         while (c != null) {
887 #if MONO_TRACE
888                                 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
889                                 string type_name = null;
890                                 if (trace != null) {
891                                         type_name = GetType ().Name;
892                                         trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
893                                 }
894 #endif
895                                 if (c.OnBubbleEvent (source, args)) {
896 #if MONO_TRACE
897                                         if (trace != null)
898                                                 trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
899 #endif
900                                         break;
901                                 }
902 #if MONO_TRACE
903                                 if (trace != null)
904                                         trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
905 #endif
906                                 c = c.Parent;
907                         }
908                 }
909
910 #if NET_2_0
911                 protected internal
912 #else
913                 protected
914 #endif
915                 virtual void Render(HtmlTextWriter writer) //DIT
916                 {
917                         RenderChildren(writer);
918                 }
919
920 #if NET_2_0
921                 protected internal
922 #else
923                 protected
924 #endif
925                 virtual void RenderChildren (HtmlTextWriter writer) //DIT
926                 {
927                         if (_renderMethodDelegate != null) {
928                                 _renderMethodDelegate (writer, this);
929                         } else if (_controls != null) {
930                                 int len = _controls.Count;
931                                 for (int i = 0; i < len; i++) {
932                                         Control c = _controls [i];
933 #if NET_2_0
934                                         if (c.Adapter != null)
935                                                 c.RenderControl (writer, c.Adapter);
936                                         else
937 #endif
938                                                 c.RenderControl (writer);
939                                 }
940                         }
941                 }
942
943 #if NET_2_0
944                 protected virtual ControlAdapter ResolveAdapter ()
945                 {
946                         throw new NotImplementedException ();
947                 }
948 #endif          
949
950                 protected virtual object SaveViewState ()
951                 {
952                         if ((stateMask & VISIBLE_CHANGED) != 0) {
953                                 ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
954                         } else if (_viewState == null) {
955                                 return null;
956                         }
957
958                         return _viewState.SaveViewState ();
959                 }
960
961                 protected virtual void TrackViewState()
962                 {
963                         if (_viewState != null)
964                                 _viewState.TrackViewState ();
965
966                         stateMask |= TRACK_VIEWSTATE;
967                 }
968
969                 public virtual void Dispose ()
970                 {
971                         if ((event_mask & disposed_mask) != 0) {
972                                 EventHandler eh = (EventHandler)(_events [DisposedEvent]);
973                                 if (eh != null) eh (this, EventArgs.Empty);
974                         }
975                 }
976
977                 [WebCategory ("FIXME")]
978                 [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
979                 public event EventHandler DataBinding {
980                         add {
981                                 event_mask |= databinding_mask;
982                                 Events.AddHandler (DataBindingEvent, value);
983                         }
984                         remove { Events.RemoveHandler (DataBindingEvent, value); }
985                 }
986
987                 [WebSysDescription ("Raised when the contol is disposed.")]
988                 public event EventHandler Disposed {
989                         add {
990                                 event_mask |= disposed_mask;
991                                 Events.AddHandler (DisposedEvent, value);
992                         }
993                         remove { Events.RemoveHandler (DisposedEvent, value); }
994                 }
995
996                 [WebSysDescription ("Raised when the page containing the control is initialized.")]
997                 public event EventHandler Init {
998                         add {
999                                 event_mask |= init_mask;
1000                                 Events.AddHandler (InitEvent, value);
1001                         }
1002                         remove { Events.RemoveHandler (InitEvent, value); }
1003                 }
1004
1005                 [WebSysDescription ("Raised after the page containing the control has been loaded.")]
1006                 public event EventHandler Load {
1007                         add {
1008                                 event_mask |= load_mask;
1009                                 Events.AddHandler (LoadEvent, value);
1010                         }
1011                         remove { Events.RemoveHandler (LoadEvent, value); }
1012                 }
1013
1014                 [WebSysDescription ("Raised before the page containing the control is rendered.")]
1015                 public event EventHandler PreRender {
1016                         add {
1017                                 event_mask |= prerender_mask;
1018                                 Events.AddHandler (PreRenderEvent, value);
1019                         }
1020                         remove { Events.RemoveHandler (PreRenderEvent, value); }
1021                 }
1022
1023                 [WebSysDescription ("Raised when the page containing the control is unloaded.")]
1024                 public event EventHandler Unload {
1025                         add {
1026                                 event_mask |= unload_mask;
1027                                 Events.AddHandler (UnloadEvent, value);
1028                         }
1029                         remove { Events.RemoveHandler (UnloadEvent, value); }
1030                 }
1031
1032                 public virtual void DataBind() //DIT
1033                 {
1034                         #if NET_2_0
1035                         DataBind (true);
1036                         #else
1037                         OnDataBinding (EventArgs.Empty);
1038                         DataBindChildren();
1039                         #endif
1040                 }
1041
1042                 #if NET_2_0
1043                 protected virtual
1044                 #endif
1045                 
1046                 void DataBindChildren ()
1047                 {
1048                         if (!HasControls ())
1049                                 return;
1050                         
1051                         int len = _controls.Count;
1052                         for (int i = 0; i < len; i++) {
1053                                 Control c = _controls [i];
1054                                 c.DataBind ();
1055                         }
1056                 }
1057
1058
1059                 public virtual bool HasControls ()
1060                 {
1061                     return (_controls != null && _controls.Count > 0);
1062                 }
1063
1064 #if NET_2_0
1065                 public virtual
1066 #else
1067                 public
1068 #endif
1069                 void RenderControl (HtmlTextWriter writer)
1070                 {
1071                         if ((stateMask & VISIBLE) != 0) {
1072                                 HttpContext ctx = Context;
1073                                 TraceContext trace = (ctx != null) ? ctx.Trace : null;
1074                                 int pos = 0;
1075                                 if ((trace != null) && trace.IsEnabled)
1076                                         pos = ctx.Response.GetOutputByteCount ();
1077
1078                                 Render(writer);
1079                                 if ((trace != null) && trace.IsEnabled) {
1080                                         int size = ctx.Response.GetOutputByteCount () - pos;
1081                                         trace.SaveSize (this, size >= 0 ? size : 0);
1082                                 }
1083                         }
1084                 }
1085
1086 #if NET_2_0
1087                 protected void RenderControl (HtmlTextWriter writer,
1088                                               ControlAdapter adapter)
1089                 {
1090                         if ((stateMask & VISIBLE) != 0) {
1091                                 adapter.BeginRender (writer);
1092                                 adapter.Render (writer);
1093                                 adapter.EndRender (writer);
1094                         }
1095                 }
1096 #endif          
1097
1098                 public string ResolveUrl (string relativeUrl)
1099                 {
1100                         if (relativeUrl == null)
1101                                 throw new ArgumentNullException ("relativeUrl");
1102
1103                         if (relativeUrl == "")
1104                                 return "";
1105
1106                         if (relativeUrl [0] == '#')
1107                                 return relativeUrl;
1108                         
1109                         string ts = TemplateSourceDirectory;
1110                         if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
1111                                 return relativeUrl;
1112
1113                         HttpResponse resp = Context.Response;
1114                         return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
1115                 }
1116                 
1117                 internal bool HasRenderMethodDelegate () {
1118                         return _renderMethodDelegate != null;
1119                 }
1120
1121                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1122                 public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
1123                 {
1124                         _renderMethodDelegate = renderMethod;
1125                 }
1126
1127                 internal void LoadRecursive()
1128                 {
1129 #if MONO_TRACE
1130                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1131                         string type_name = null;
1132                         if (trace != null) {
1133                                 type_name = GetType ().Name;
1134                                 trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
1135                         }
1136 #endif
1137 #if NET_2_0
1138                         if (Adapter != null)
1139                                 Adapter.OnLoad (EventArgs.Empty);
1140                         else
1141 #endif
1142                                 OnLoad (EventArgs.Empty);
1143                         if (HasControls ()) {
1144                                 int len = _controls.Count;
1145                                 for (int i=0;i<len;i++)
1146                                 {
1147                                         Control c = _controls[i];
1148                                         c.LoadRecursive ();
1149                                 }
1150                         }
1151
1152 #if MONO_TRACE
1153                         if (trace != null)
1154                                 trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
1155 #endif
1156                         stateMask |= LOADED;
1157                 }
1158
1159                 internal void UnloadRecursive(Boolean dispose)
1160                 {
1161 #if MONO_TRACE
1162                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1163                         string type_name = null;
1164                         if (trace != null) {
1165                                 type_name = GetType ().Name;
1166                                 trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
1167                         }
1168 #endif
1169                         if (HasControls ()) {
1170                                 int len = _controls.Count;
1171                                 for (int i=0;i<len;i++)
1172                                 {
1173                                         Control c = _controls[i];                                       
1174                                         c.UnloadRecursive (dispose);
1175                                 }
1176                         }
1177
1178 #if MONO_TRACE
1179                         if (trace != null)
1180                                 trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
1181 #endif
1182 #if NET_2_0
1183                         if (Adapter != null)
1184                                 Adapter.OnUnload (EventArgs.Empty);
1185                         else
1186 #endif
1187                                 OnUnload (EventArgs.Empty);
1188                         if (dispose)
1189                                 Dispose();
1190                 }
1191
1192                 internal void PreRenderRecursiveInternal()
1193                 {
1194                         if ((stateMask & VISIBLE) != 0) {
1195                                 EnsureChildControls ();
1196 #if MONO_TRACE
1197                                 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1198                                 string type_name = null;
1199                                 if (trace != null) {
1200                                         type_name = GetType ().Name;
1201                                         trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
1202                                 }
1203 #endif
1204 #if NET_2_0
1205                                 if (Adapter != null)
1206                                         Adapter.OnPreRender (EventArgs.Empty);
1207                                 else
1208 #endif
1209                                         OnPreRender (EventArgs.Empty);
1210                                 if (!HasControls ())
1211                                         return;
1212                                 
1213                                 int len = _controls.Count;
1214                                 for (int i=0;i<len;i++)
1215                                 {
1216                                         Control c = _controls[i];
1217                                         c.PreRenderRecursiveInternal ();
1218                                 }
1219 #if MONO_TRACE
1220                                 if (trace != null)
1221                                         trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
1222 #endif
1223                         }
1224                         stateMask |= PRERENDERED;
1225                 }
1226
1227                 internal void InitRecursive(Control namingContainer)
1228                 {
1229 #if MONO_TRACE
1230                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1231                         string type_name = null;
1232                         if (trace != null) {
1233                                 type_name = GetType ().Name;
1234                                 trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
1235                         }
1236 #endif
1237
1238                         if (HasControls ()) {
1239                                 if ((stateMask & IS_NAMING_CONTAINER) != 0)
1240                                         namingContainer = this;
1241
1242                                 if (namingContainer != null && 
1243                                     namingContainer._userId == null &&
1244                                     namingContainer.AutoID)
1245                                         namingContainer._userId = namingContainer.GetDefaultName () + "b";
1246
1247                                 int len = _controls.Count;
1248                                 for (int i=0;i<len;i++)
1249                                 {
1250                                         Control c = _controls[i];
1251                                         c._page = Page;
1252                                         c._namingContainer = namingContainer;
1253                                         if (namingContainer != null && c._userId == null && c.AutoID)
1254                                                 c._userId = namingContainer.GetDefaultName () + "c";
1255                                         c.InitRecursive (namingContainer);      
1256                                 }
1257                         }
1258
1259                         stateMask |= INITING;
1260 #if NET_2_0
1261                         if (Adapter != null)
1262                                 Adapter.OnInit (EventArgs.Empty);
1263                         else
1264 #endif
1265                                 OnInit (EventArgs.Empty);
1266 #if MONO_TRACE
1267                         if (trace != null)
1268                                 trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
1269 #endif
1270                         TrackViewState ();
1271                         stateMask |= INITED;
1272                         stateMask &= ~INITING;
1273                 }
1274
1275                 internal object SaveViewStateRecursive ()
1276                 {
1277                         if (!EnableViewState)
1278                                 return null;
1279
1280 #if MONO_TRACE
1281                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1282                         string type_name = null;
1283                         if (trace != null) {
1284                                 type_name = GetType ().Name;
1285                                 trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
1286                         }
1287 #endif
1288
1289                         ArrayList controlList = null;
1290                         ArrayList controlStates = null;
1291
1292                         int idx = -1;
1293                         if (HasControls ())
1294                         {
1295                                 int len = _controls.Count;
1296                                 for (int i=0;i<len;i++)
1297                                 {
1298                                         Control ctrl = _controls[i];
1299                                         object ctrlState = ctrl.SaveViewStateRecursive ();
1300                                         idx++;
1301                                         if (ctrlState == null)
1302                                                 continue;
1303
1304                                         if (controlList == null) 
1305                                         {
1306                                                 controlList = new ArrayList ();
1307                                                 controlStates = new ArrayList ();
1308                                         }
1309
1310                                         controlList.Add (idx);
1311                                         controlStates.Add (ctrlState);
1312                                 }
1313                         }
1314
1315                         object thisState = SaveViewState ();
1316                         if (thisState == null && controlList == null && controlStates == null) {
1317 #if MONO_TRACE
1318                                 if (trace != null) {
1319                                         trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
1320                                         trace.SaveViewState (this, null);
1321                                 }
1322 #endif
1323                                 return null;
1324                         }
1325
1326 #if MONO_TRACE
1327                         if (trace != null) {
1328                                 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
1329                                 trace.SaveViewState (this, thisState);
1330                         }
1331 #endif
1332                         return new Triplet (thisState, controlList, controlStates);
1333                 }
1334                 
1335                 internal void LoadViewStateRecursive (object savedState)
1336                 {
1337                         if (!EnableViewState || savedState == null)
1338                                 return;
1339
1340 #if MONO_TRACE
1341                         TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1342                         string type_name = null;
1343                         if (trace != null) {
1344                                 type_name = GetType ().Name;
1345                                 trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
1346                         }
1347 #endif
1348                         Triplet savedInfo = (Triplet) savedState;
1349                         LoadViewState (savedInfo.First);
1350
1351                         ArrayList controlList = savedInfo.Second as ArrayList;
1352                         if (controlList == null)
1353                                 return;
1354                         ArrayList controlStates = savedInfo.Third as ArrayList;
1355                         int nControls = controlList.Count;
1356                         for (int i = 0; i < nControls; i++) {
1357                                 int k = (int) controlList [i];
1358                                 if (k < Controls.Count && controlStates != null) {
1359                                         Control c = Controls [k];
1360                                         c.LoadViewStateRecursive (controlStates [i]);
1361                                 } else {
1362                                         if (pendingVS == null)
1363                                                 pendingVS = new Hashtable ();
1364
1365                                         pendingVS [k] = controlStates [i];
1366                                 }
1367                         }
1368
1369 #if MONO_TRACE
1370                         if (trace != null)
1371                                 trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
1372 #endif
1373                         stateMask |= VIEWSTATE_LOADED;
1374                 }
1375                 
1376                 internal bool AutoID
1377                 {
1378                         get { return (stateMask & AUTOID) != 0; }
1379                         set {
1380                                 if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
1381                                         return;
1382
1383                                 SetMask (AUTOID, value);
1384                         }
1385                 }
1386
1387                 protected internal virtual void RemovedControl (Control control)
1388                 {
1389                         control.UnloadRecursive (false);
1390                         control._parent = null;
1391                         control._page = null;
1392                         control._namingContainer = null;
1393                 }
1394
1395
1396 #if NET_2_0
1397
1398                 string skinId = string.Empty;
1399                 
1400                 [Browsable (false)]
1401                 [Themeable (false)]
1402                 [DefaultValue (true)]
1403                 public virtual bool EnableTheming
1404                 {
1405                         get { return (stateMask & ENABLE_THEMING) != 0; }
1406                         set { SetMask (ENABLE_THEMING, value); }
1407                 }
1408                 
1409                 [Browsable (false)]
1410                 [DefaultValue ("")]
1411                 [Filterable (false)]
1412                 public virtual string SkinID
1413                 {
1414                         get { return skinId; }
1415                         set { skinId = value; }
1416                 }
1417                 
1418                 public string ResolveClientUrl (string url)
1419                 {
1420                         throw new NotImplementedException ();               
1421                 }
1422
1423                 ControlBuilder IControlBuilderAccessor.ControlBuilder { 
1424                         get {throw new NotImplementedException (); }
1425                 }
1426
1427                 IDictionary IControlDesignerAccessor.GetDesignModeState ()
1428                 {
1429                         throw new NotImplementedException ();               
1430                 }
1431
1432                 void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
1433                 {
1434                         SetDesignModeState (designData);
1435                 }
1436         
1437                 void IControlDesignerAccessor.SetOwnerControl (Control control)
1438                 {
1439                         throw new NotImplementedException ();               
1440                 }
1441                 
1442                 IDictionary IControlDesignerAccessor.UserData { 
1443                         get { throw new NotImplementedException (); }
1444                 }
1445        
1446                 ExpressionBindingCollection expressionBindings;
1447
1448                 ExpressionBindingCollection IExpressionsAccessor.Expressions { 
1449                         get { 
1450                                 if (expressionBindings == null)
1451                                         expressionBindings = new ExpressionBindingCollection ();
1452                                 return expressionBindings;
1453                         } 
1454                 }
1455                 
1456                 bool IExpressionsAccessor.HasExpressions { 
1457                         get {
1458                                 return (expressionBindings != null && expressionBindings.Count > 0);
1459                         }
1460                 }
1461
1462                 [MonoTODO]
1463                 public virtual void Focus()
1464                 {
1465                         throw new NotImplementedException();
1466                 }
1467                 
1468                 protected internal virtual void LoadControlState (object state)
1469                 {
1470                 }
1471                 
1472                 protected internal virtual object SaveControlState ()
1473                 {
1474                         return null;
1475                 }
1476                 
1477                 protected virtual void DataBind (bool raiseOnDataBinding)
1478                 {
1479                         bool foundDataItem = false;
1480                         
1481                         if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
1482                                 object o = DataBinder.GetDataItem (this, out foundDataItem);
1483                                 if (foundDataItem)
1484                                         Page.PushDataItemContext (o);
1485                         }
1486                         
1487                         try {
1488                                 
1489                                 if (raiseOnDataBinding)
1490                                         OnDataBinding (EventArgs.Empty);
1491                                 DataBindChildren();
1492                         
1493                         } finally {
1494                                 if (foundDataItem)
1495                                         Page.PopDataItemContext ();
1496                         }
1497                 }
1498                 
1499                 protected virtual IDictionary GetDesignModeState ()
1500                 {
1501                         throw new NotImplementedException ();               
1502                 }
1503                 
1504                 protected virtual void SetDesignModeState (IDictionary data)
1505                 {
1506                         throw new NotImplementedException ();               
1507                 }
1508 #endif
1509                 void IParserAccessor.AddParsedSubObject (object obj) {
1510                         this.AddParsedSubObject (obj);
1511                 }
1512
1513                 DataBindingCollection IDataBindingsAccessor.DataBindings {
1514                         get {
1515                                 if (dataBindings == null) {
1516                                         dataBindings = new DataBindingCollection ();
1517                                 }
1518                                 return dataBindings;
1519                         }
1520                 }
1521
1522                 bool IDataBindingsAccessor.HasDataBindings {
1523                         get {
1524                                 if (dataBindings != null && dataBindings.Count > 0) {
1525                                         return true;
1526                                 }
1527                                 return false;
1528                         }
1529                 }
1530         }
1531 }