2 // System.Web.UI.Control.cs
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)
11 // (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
12 // (C) 2004 Novell, Inc. (http://www.novell.com)
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:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
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.
36 // This will provide extra information when trace is enabled. Might be too verbose.
39 using System.Collections;
40 using System.ComponentModel;
41 using System.ComponentModel.Design;
42 using System.ComponentModel.Design.Serialization;
43 using System.Security.Permissions;
45 using System.Web.Util;
47 using System.Web.UI.Adapters;
51 namespace System.Web.UI
54 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
55 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
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")]
61 [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web,
62 "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
66 [DesignerSerializer ("Microsoft.VSDesigner.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner,
67 "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
69 public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
71 , IUrlResolutionService, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
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;
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;
93 ControlCollection _controls;
94 IDictionary _childViewStates;
95 Control _namingContainer;
101 EventHandlerList _events;
102 RenderMethod _renderMethodDelegate;
105 DataBindingCollection dataBindings;
106 Hashtable pendingVS; // may hold unused viewstate data from child controls
111 const int ENABLE_VIEWSTATE = 1;
112 const int VISIBLE = 1 << 1;
113 const int AUTOID = 1 << 2;
114 const int CREATING_CONTROLS = 1 << 3;
115 const int BINDING_CONTAINER = 1 << 4;
116 const int AUTO_EVENT_WIREUP = 1 << 5;
117 const int IS_NAMING_CONTAINER = 1 << 6;
118 const int VISIBLE_CHANGED = 1 << 7;
119 const int TRACK_VIEWSTATE = 1 << 8;
120 const int CHILD_CONTROLS_CREATED = 1 << 9;
121 const int ID_SET = 1 << 10;
122 const int INITED = 1 << 11;
123 const int INITING = 1 << 12;
124 const int VIEWSTATE_LOADED = 1 << 13;
125 const int LOADED = 1 << 14;
126 const int PRERENDERED = 1 << 15;
128 const int ENABLE_THEMING = 1 << 16;
134 defaultNameArray = new string [100];
135 for (int i = 0 ; i < 100 ; i++)
136 defaultNameArray [i] = "_ctl" + i;
141 stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
142 if (this is INamingContainer)
143 stateMask |= IS_NAMING_CONTAINER;
148 protected ControlAdapter Adapter
151 // for the time being, fool the
152 // Control machinery into thinking we
153 // don't have an Adapter. This will
154 // allow us to write all the rest of
155 // the Adapter handling code without
156 // having to worry about *having*
162 [EditorBrowsable (EditorBrowsableState.Advanced)]
164 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
165 public string AppRelativeTemplateSourceDirectory
168 throw new NotImplementedException ();
170 [EditorBrowsable (EditorBrowsableState.Never)]
172 throw new NotImplementedException ();
178 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
179 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
180 public Control BindingContainer {
182 Control container = NamingContainer;
183 if ((container.stateMask & BINDING_CONTAINER) == 0)
184 container = container.BindingContainer;
189 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
191 [WebSysDescription ("An Identification of the control that is rendered.")]
192 public virtual string ClientID {
194 string client = UniqueID;
197 client = client.Replace (':', '_');
204 protected char ClientIDSeparator
207 throw new NotImplementedException ();
212 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
214 [WebSysDescription ("The child controls of this control.")]
215 public virtual ControlCollection Controls //DIT
219 if (_controls == null) _controls = CreateControlCollection();
225 protected internal bool DesignMode
228 throw new NotImplementedException ();
233 [DefaultValue (true), WebCategory ("Behavior")]
234 [WebSysDescription ("An Identification of the control that is rendered.")]
238 public virtual bool EnableViewState {
239 get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
240 set { SetMask (ENABLE_VIEWSTATE, value); }
243 [MergableProperty (false), ParenthesizePropertyName (true)]
244 [WebSysDescription ("The name of the control that is rendered.")]
246 [Filterable (false), Themeable (false)]
249 public virtual string ID {
251 return (((stateMask & ID_SET) != 0) ? _userId : null);
265 protected char IdSeparator
268 throw new NotImplementedException ();
272 protected internal bool IsChildControlStateCleared
275 throw new NotImplementedException ();
279 protected internal bool IsViewStateEnabled
282 throw new NotImplementedException ();
286 protected bool LoadViewStateByID
289 throw new NotImplementedException ();
294 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
296 [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
297 public virtual Control NamingContainer {
299 if (_namingContainer == null && _parent != null) {
300 if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
301 _namingContainer = _parent.NamingContainer;
303 _namingContainer = _parent;
306 return _namingContainer;
310 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
312 [WebSysDescription ("The webpage that this control resides on.")]
316 public virtual Page Page //DIT
320 if (_page == null && _parent != null) _page = _parent.Page;
329 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
331 [WebSysDescription ("The parent control of this control.")]
332 public virtual Control Parent //DIT
340 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
341 [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
342 [WebSysDescription ("The site this control is part of.")]
343 public ISite Site //DIT
357 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
358 public TemplateControl TemplateControl
361 throw new NotImplementedException ();
363 [EditorBrowsable (EditorBrowsableState.Never)]
365 throw new NotImplementedException ();
370 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
372 [WebSysDescription ("A virtual directory containing the parent of the control.")]
373 public virtual string TemplateSourceDirectory {
374 get { return (_parent == null) ? String.Empty : _parent.TemplateSourceDirectory; }
377 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
379 [WebSysDescription ("The unique ID of the control.")]
380 public virtual string UniqueID {
382 if (uniqueID != null)
385 if (_namingContainer == null) {
390 _userId = _namingContainer.GetDefaultName ();
392 string prefix = _namingContainer.UniqueID;
393 if (_namingContainer == _page || prefix == null) {
398 uniqueID = prefix + ":" + _userId;
403 void SetMask (int m, bool val)
411 [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
412 [WebSysDescription ("Visiblity state of the control.")]
413 public virtual bool Visible {
415 if ((stateMask & VISIBLE) == 0)
419 return _parent.Visible;
425 if ((value && (stateMask & VISIBLE) == 0) ||
426 (!value && (stateMask & VISIBLE) != 0)) {
427 if (IsTrackingViewState)
428 stateMask |= VISIBLE_CHANGED;
431 SetMask (VISIBLE, value);
435 protected bool ChildControlsCreated {
436 get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
438 if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0)
441 SetMask (CHILD_CONTROLS_CREATED, value);
446 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
447 protected virtual HttpContext Context //DIT
452 if (_context != null)
455 return HttpContext.Current;
456 context = _parent.Context;
459 return HttpContext.Current;
462 protected EventHandlerList Events //DIT
468 _events = new EventHandlerList();
473 protected bool HasChildViewState //DIT
477 if (_childViewStates == null) return false;
482 protected bool IsTrackingViewState {
483 get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
487 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
488 [WebSysDescription ("ViewState")]
489 protected virtual StateBag ViewState
493 if(_viewState == null)
494 _viewState = new StateBag (ViewStateIgnoresCase);
496 if (IsTrackingViewState)
497 _viewState.TrackViewState ();
504 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
505 protected virtual bool ViewStateIgnoresCase
512 internal bool AutoEventWireup {
513 get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
514 set { SetMask (AUTO_EVENT_WIREUP, value); }
517 internal void SetBindingContainer (bool isBC)
519 SetMask (BINDING_CONTAINER, isBC);
522 internal void ResetChildNames ()
527 string GetDefaultName ()
530 if (defaultNumberID > 99) {
531 defaultName = "_ctl" + defaultNumberID++;
533 defaultName = defaultNameArray [defaultNumberID++];
538 void NullifyUniqueID ()
544 foreach (Control c in Controls)
545 c.NullifyUniqueID ();
548 protected internal virtual void AddedControl (Control control, int index)
550 /* Ensure the control don't have more than 1 parent */
551 if (control._parent != null)
552 control._parent.Controls.Remove (control);
554 control._parent = this;
555 control._page = _page;
556 Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
559 control._namingContainer = nc;
560 if (control.AutoID == true && control._userId == null)
561 control._userId = nc.GetDefaultName ();
564 if ((stateMask & (INITING | INITED)) != 0)
565 control.InitRecursive (nc);
567 if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
568 if (pendingVS != null) {
569 object vs = pendingVS [index];
571 pendingVS.Remove (index);
572 if (pendingVS.Count == 0)
575 control.LoadViewStateRecursive (vs);
580 if ((stateMask & LOADED) != 0)
581 control.LoadRecursive ();
583 if ((stateMask & PRERENDERED) != 0)
584 control.PreRenderRecursiveInternal ();
587 protected virtual void AddParsedSubObject(object obj) //DIT
589 Control c = obj as Control;
590 if (c != null) Controls.Add(c);
594 [EditorBrowsable (EditorBrowsableState.Advanced)]
595 public virtual void ApplyStyleSheetSkin (Page page)
597 throw new NotImplementedException ();
601 protected void BuildProfileTree(string parentId, bool calcViewState)
607 protected void ClearChildControlState ()
609 throw new NotImplementedException ();
612 protected void ClearChildState ()
614 throw new NotImplementedException ();
618 protected void ClearChildViewState ()
628 virtual void CreateChildControls() {} //DIT
630 protected virtual ControlCollection CreateControlCollection() //DIT
632 return new ControlCollection(this);
635 protected virtual void EnsureChildControls ()
637 if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
638 stateMask |= CREATING_CONTROLS;
641 Adapter.CreateChildControls ();
644 CreateChildControls();
645 ChildControlsCreated = true;
646 stateMask &= ~CREATING_CONTROLS;
651 protected void EnsureID ()
653 throw new NotImplementedException ();
656 protected bool HasEvents ()
658 throw new NotImplementedException ();
664 protected bool IsLiteralContent()
666 if (HasControls () && Controls.Count == 1 && (Controls [0] is LiteralControl))
672 [WebSysDescription ("")]
673 public virtual Control FindControl (string id)
675 return FindControl (id, 0);
678 Control LookForControlByName (string id)
683 Control result = null;
684 foreach (Control c in Controls) {
685 if (String.Compare (id, c._userId, true) == 0) {
686 if (result != null && result != c) {
687 throw new HttpException ("1 Found more than one control with ID '" + id + "'");
694 if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
695 Control child = c.LookForControlByName (id);
697 if (result != null && result != child)
698 throw new HttpException ("2 Found more than one control with ID '" + id + "'");
708 protected virtual Control FindControl (string id, int pathOffset)
710 EnsureChildControls ();
711 Control namingContainer = null;
712 if ((stateMask & IS_NAMING_CONTAINER) == 0) {
713 namingContainer = NamingContainer;
714 if (namingContainer == null)
717 return namingContainer.FindControl (id, pathOffset);
723 int colon = id.IndexOf (':', pathOffset);
725 return LookForControlByName (id.Substring (pathOffset));
727 string idfound = id.Substring (pathOffset, colon - pathOffset);
728 namingContainer = LookForControlByName (idfound);
729 if (namingContainer == null)
732 return namingContainer.FindControl (id, colon + 1);
735 protected virtual void LoadViewState(object savedState)
737 if (savedState != null) {
738 ViewState.LoadViewState (savedState);
739 object o = ViewState ["Visible"];
741 SetMask (VISIBLE, (bool) o);
742 stateMask |= VISIBLE_CHANGED;
747 [MonoTODO("Secure?")]
748 protected string MapPathSecure(string virtualPath)
750 string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
751 return Context.Request.MapPath (combined);
754 protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
757 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
758 string type_name = null;
760 type_name = GetType ().Name;
761 trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
767 protected virtual void OnDataBinding (EventArgs e)
769 if ((event_mask & databinding_mask) != 0) {
770 EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
773 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
774 string type_name = null;
776 type_name = GetType ().Name;
777 trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
790 virtual void OnInit (EventArgs e)
792 if ((event_mask & init_mask) != 0) {
793 EventHandler eh = (EventHandler)(_events [InitEvent]);
796 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
797 string type_name = null;
799 type_name = GetType ().Name;
800 trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
813 virtual void OnLoad (EventArgs e)
815 if ((event_mask & load_mask) != 0) {
816 EventHandler eh = (EventHandler)(_events [LoadEvent]);
819 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
820 string type_name = null;
822 type_name = GetType ().Name;
823 trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
836 virtual void OnPreRender (EventArgs e)
838 if ((event_mask & prerender_mask) != 0) {
839 EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
842 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
843 string type_name = null;
845 type_name = GetType ().Name;
846 trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
859 virtual void OnUnload(EventArgs e)
861 if ((event_mask & unload_mask) != 0) {
862 EventHandler eh = (EventHandler)(_events [UnloadEvent]);
865 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
866 string type_name = null;
868 type_name = GetType ().Name;
869 trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
878 protected internal Stream OpenFile (string path)
880 throw new NotImplementedException ();
884 protected void RaiseBubbleEvent(object source, EventArgs args)
889 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
890 string type_name = null;
892 type_name = GetType ().Name;
893 trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
896 if (c.OnBubbleEvent (source, args)) {
899 trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
905 trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
916 virtual void Render(HtmlTextWriter writer) //DIT
918 RenderChildren(writer);
926 virtual void RenderChildren (HtmlTextWriter writer) //DIT
928 if (_renderMethodDelegate != null) {
929 _renderMethodDelegate (writer, this);
930 } else if (HasControls ()) {
931 int len = Controls.Count;
932 for (int i = 0; i < len; i++) {
933 Control c = Controls [i];
935 if (c.Adapter != null)
936 c.RenderControl (writer, c.Adapter);
939 c.RenderControl (writer);
945 protected virtual ControlAdapter ResolveAdapter ()
947 throw new NotImplementedException ();
951 protected virtual object SaveViewState ()
953 if ((stateMask & VISIBLE_CHANGED) != 0) {
954 ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
955 } else if (_viewState == null) {
959 return _viewState.SaveViewState ();
962 protected virtual void TrackViewState()
964 if (_viewState != null)
965 _viewState.TrackViewState ();
967 stateMask |= TRACK_VIEWSTATE;
970 public virtual void Dispose ()
972 if ((event_mask & disposed_mask) != 0) {
973 EventHandler eh = (EventHandler)(_events [DisposedEvent]);
974 if (eh != null) eh (this, EventArgs.Empty);
978 [WebCategory ("FIXME")]
979 [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
980 public event EventHandler DataBinding {
982 event_mask |= databinding_mask;
983 Events.AddHandler (DataBindingEvent, value);
985 remove { Events.RemoveHandler (DataBindingEvent, value); }
988 [WebSysDescription ("Raised when the contol is disposed.")]
989 public event EventHandler Disposed {
991 event_mask |= disposed_mask;
992 Events.AddHandler (DisposedEvent, value);
994 remove { Events.RemoveHandler (DisposedEvent, value); }
997 [WebSysDescription ("Raised when the page containing the control is initialized.")]
998 public event EventHandler Init {
1000 event_mask |= init_mask;
1001 Events.AddHandler (InitEvent, value);
1003 remove { Events.RemoveHandler (InitEvent, value); }
1006 [WebSysDescription ("Raised after the page containing the control has been loaded.")]
1007 public event EventHandler Load {
1009 event_mask |= load_mask;
1010 Events.AddHandler (LoadEvent, value);
1012 remove { Events.RemoveHandler (LoadEvent, value); }
1015 [WebSysDescription ("Raised before the page containing the control is rendered.")]
1016 public event EventHandler PreRender {
1018 event_mask |= prerender_mask;
1019 Events.AddHandler (PreRenderEvent, value);
1021 remove { Events.RemoveHandler (PreRenderEvent, value); }
1024 [WebSysDescription ("Raised when the page containing the control is unloaded.")]
1025 public event EventHandler Unload {
1027 event_mask |= unload_mask;
1028 Events.AddHandler (UnloadEvent, value);
1030 remove { Events.RemoveHandler (UnloadEvent, value); }
1033 public virtual void DataBind() //DIT
1038 OnDataBinding (EventArgs.Empty);
1047 void DataBindChildren ()
1049 if (!HasControls ())
1052 int len = Controls.Count;
1053 for (int i = 0; i < len; i++) {
1054 Control c = Controls [i];
1060 public virtual bool HasControls ()
1062 return (_controls != null && _controls.Count > 0);
1070 void RenderControl (HtmlTextWriter writer)
1072 if ((stateMask & VISIBLE) != 0)
1077 protected void RenderControl (HtmlTextWriter writer,
1078 ControlAdapter adapter)
1080 if ((stateMask & VISIBLE) != 0) {
1081 adapter.BeginRender (writer);
1082 adapter.Render (writer);
1083 adapter.EndRender (writer);
1088 public string ResolveUrl (string relativeUrl)
1090 if (relativeUrl == null)
1091 throw new ArgumentNullException ("relativeUrl");
1093 if (relativeUrl == "")
1096 if (relativeUrl [0] == '#')
1099 string ts = TemplateSourceDirectory;
1100 if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
1103 HttpResponse resp = Context.Response;
1104 return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
1107 internal bool HasRenderMethodDelegate () {
1108 return _renderMethodDelegate != null;
1111 [EditorBrowsable (EditorBrowsableState.Advanced)]
1112 public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
1114 _renderMethodDelegate = renderMethod;
1117 internal void LoadRecursive()
1120 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1121 string type_name = null;
1122 if (trace != null) {
1123 type_name = GetType ().Name;
1124 trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
1128 if (Adapter != null)
1129 Adapter.OnLoad (EventArgs.Empty);
1132 OnLoad (EventArgs.Empty);
1133 if (HasControls ()) {
1134 int len = Controls.Count;
1135 for (int i=0;i<len;i++)
1137 Control c = Controls[i];
1144 trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
1146 stateMask |= LOADED;
1149 internal void UnloadRecursive(Boolean dispose)
1152 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1153 string type_name = null;
1154 if (trace != null) {
1155 type_name = GetType ().Name;
1156 trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
1159 if (HasControls ()) {
1160 int len = Controls.Count;
1161 for (int i=0;i<len;i++)
1163 Control c = Controls[i];
1164 c.UnloadRecursive (dispose);
1170 trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
1173 if (Adapter != null)
1174 Adapter.OnUnload (EventArgs.Empty);
1177 OnUnload (EventArgs.Empty);
1182 internal void PreRenderRecursiveInternal()
1184 if ((stateMask & VISIBLE) != 0) {
1185 EnsureChildControls ();
1187 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1188 string type_name = null;
1189 if (trace != null) {
1190 type_name = GetType ().Name;
1191 trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
1195 if (Adapter != null)
1196 Adapter.OnPreRender (EventArgs.Empty);
1199 OnPreRender (EventArgs.Empty);
1200 if (!HasControls ())
1203 int len = Controls.Count;
1204 for (int i=0;i<len;i++)
1206 Control c = Controls[i];
1207 c.PreRenderRecursiveInternal ();
1211 trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
1214 stateMask |= PRERENDERED;
1217 internal void InitRecursive(Control namingContainer)
1220 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1221 string type_name = null;
1222 if (trace != null) {
1223 type_name = GetType ().Name;
1224 trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
1228 if (HasControls ()) {
1229 if ((stateMask & IS_NAMING_CONTAINER) != 0)
1230 namingContainer = this;
1232 if (namingContainer != null &&
1233 namingContainer._userId == null &&
1234 namingContainer.AutoID)
1235 namingContainer._userId = namingContainer.GetDefaultName () + "b";
1237 int len = Controls.Count;
1238 for (int i=0;i<len;i++)
1240 Control c = Controls[i];
1242 c._namingContainer = namingContainer;
1243 if (namingContainer != null && c._userId == null && c.AutoID)
1244 c._userId = namingContainer.GetDefaultName () + "c";
1245 c.InitRecursive (namingContainer);
1249 stateMask |= INITING;
1251 if (Adapter != null)
1252 Adapter.OnInit (EventArgs.Empty);
1255 OnInit (EventArgs.Empty);
1258 trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
1261 stateMask |= INITED;
1262 stateMask &= ~INITING;
1265 internal object SaveViewStateRecursive ()
1267 if (!EnableViewState)
1271 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1272 string type_name = null;
1273 if (trace != null) {
1274 type_name = GetType ().Name;
1275 trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
1279 ArrayList controlList = null;
1280 ArrayList controlStates = null;
1285 int len = Controls.Count;
1286 for (int i=0;i<len;i++)
1288 Control ctrl = Controls[i];
1289 object ctrlState = ctrl.SaveViewStateRecursive ();
1291 if (ctrlState == null)
1294 if (controlList == null)
1296 controlList = new ArrayList ();
1297 controlStates = new ArrayList ();
1300 controlList.Add (idx);
1301 controlStates.Add (ctrlState);
1305 object thisState = SaveViewState ();
1306 if (thisState == null && controlList == null && controlStates == null) {
1308 if (trace != null) {
1309 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
1310 trace.SaveViewState (this, null);
1317 if (trace != null) {
1318 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
1319 trace.SaveViewState (this, thisState);
1322 return new Triplet (thisState, controlList, controlStates);
1325 internal void LoadViewStateRecursive (object savedState)
1327 if (!EnableViewState || savedState == null)
1331 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1332 string type_name = null;
1333 if (trace != null) {
1334 type_name = GetType ().Name;
1335 trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
1338 Triplet savedInfo = (Triplet) savedState;
1339 LoadViewState (savedInfo.First);
1341 ArrayList controlList = savedInfo.Second as ArrayList;
1342 if (controlList == null)
1344 ArrayList controlStates = savedInfo.Third as ArrayList;
1345 int nControls = controlList.Count;
1346 for (int i = 0; i < nControls; i++) {
1347 int k = (int) controlList [i];
1348 if (k < Controls.Count && controlStates != null) {
1349 Control c = Controls [k];
1350 c.LoadViewStateRecursive (controlStates [i]);
1352 if (pendingVS == null)
1353 pendingVS = new Hashtable ();
1355 pendingVS [k] = controlStates [i];
1361 trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
1363 stateMask |= VIEWSTATE_LOADED;
1366 internal bool AutoID
1368 get { return (stateMask & AUTOID) != 0; }
1370 if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
1373 SetMask (AUTOID, value);
1377 internal void PreventAutoID()
1382 protected internal virtual void RemovedControl (Control control)
1384 control.UnloadRecursive (false);
1385 control._parent = null;
1386 control._page = null;
1387 control._namingContainer = null;
1393 string skinId = string.Empty;
1397 [DefaultValue (true)]
1398 public virtual bool EnableTheming
1400 get { return (stateMask & ENABLE_THEMING) != 0; }
1401 set { SetMask (ENABLE_THEMING, value); }
1406 [Filterable (false)]
1407 public virtual string SkinID
1409 get { return skinId; }
1410 set { skinId = value; }
1413 public string ResolveClientUrl (string url)
1415 throw new NotImplementedException ();
1418 ControlBuilder IControlBuilderAccessor.ControlBuilder {
1419 get {throw new NotImplementedException (); }
1422 IDictionary IControlDesignerAccessor.GetDesignModeState ()
1424 throw new NotImplementedException ();
1427 void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
1429 SetDesignModeState (designData);
1432 void IControlDesignerAccessor.SetOwnerControl (Control control)
1434 throw new NotImplementedException ();
1437 IDictionary IControlDesignerAccessor.UserData {
1438 get { throw new NotImplementedException (); }
1441 ExpressionBindingCollection expressionBindings;
1443 ExpressionBindingCollection IExpressionsAccessor.Expressions {
1445 if (expressionBindings == null)
1446 expressionBindings = new ExpressionBindingCollection ();
1447 return expressionBindings;
1451 bool IExpressionsAccessor.HasExpressions {
1453 return (expressionBindings != null && expressionBindings.Count > 0);
1458 public virtual void Focus()
1460 throw new NotImplementedException();
1463 protected internal virtual void LoadControlState (object state)
1467 protected internal virtual object SaveControlState ()
1472 protected virtual void DataBind (bool raiseOnDataBinding)
1474 bool foundDataItem = false;
1476 if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
1477 object o = DataBinder.GetDataItem (this, out foundDataItem);
1479 Page.PushDataItemContext (o);
1484 if (raiseOnDataBinding)
1485 OnDataBinding (EventArgs.Empty);
1490 Page.PopDataItemContext ();
1494 protected virtual IDictionary GetDesignModeState ()
1496 throw new NotImplementedException ();
1499 protected virtual void SetDesignModeState (IDictionary data)
1501 throw new NotImplementedException ();
1504 void IParserAccessor.AddParsedSubObject (object obj) {
1505 this.AddParsedSubObject (obj);
1508 DataBindingCollection IDataBindingsAccessor.DataBindings {
1510 if (dataBindings == null) {
1511 dataBindings = new DataBindingCollection ();
1513 return dataBindings;
1517 bool IDataBindingsAccessor.HasDataBindings {
1519 if (dataBindings != null && dataBindings.Count > 0) {