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.
40 using System.Collections;
41 using System.ComponentModel;
42 using System.ComponentModel.Design;
43 using System.ComponentModel.Design.Serialization;
45 using System.Web.Util;
47 using System.Web.UI.Adapters;
51 namespace System.Web.UI
53 [DefaultProperty ("ID"), DesignerCategory ("Code"), ToolboxItemFilter ("System.Web.UI", ToolboxItemFilterType.Require)]
54 [ToolboxItem ("System.Web.UI.Design.WebControlToolboxItem, " + Consts.AssemblySystem_Design)]
55 [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
57 [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web,
58 "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
62 [DesignerSerializer ("Microsoft.VSDesigner.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner,
63 "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
65 public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
67 , IUrlResolutionService, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
70 static readonly object DataBindingEvent = new object();
71 static readonly object DisposedEvent = new object();
72 static readonly object InitEvent = new object();
73 static readonly object LoadEvent = new object();
74 static readonly object PreRenderEvent = new object();
75 static readonly object UnloadEvent = new object();
76 static string[] defaultNameArray;
79 const int databinding_mask = 1;
80 const int disposed_mask = 1 << 1;
81 const int init_mask = 1 << 2;
82 const int load_mask = 1 << 3;
83 const int prerender_mask = 1 << 4;
84 const int unload_mask = 1 << 5;
89 ControlCollection _controls;
90 Control _namingContainer;
96 EventHandlerList _events;
97 RenderMethod _renderMethodDelegate;
100 DataBindingCollection dataBindings;
101 Hashtable pendingVS; // may hold unused viewstate data from child controls
106 const int ENABLE_VIEWSTATE = 1;
107 const int VISIBLE = 1 << 1;
108 const int AUTOID = 1 << 2;
109 const int CREATING_CONTROLS = 1 << 3;
110 const int BINDING_CONTAINER = 1 << 4;
111 const int AUTO_EVENT_WIREUP = 1 << 5;
112 const int IS_NAMING_CONTAINER = 1 << 6;
113 const int VISIBLE_CHANGED = 1 << 7;
114 const int TRACK_VIEWSTATE = 1 << 8;
115 const int CHILD_CONTROLS_CREATED = 1 << 9;
116 const int ID_SET = 1 << 10;
117 const int INITED = 1 << 11;
118 const int INITING = 1 << 12;
119 const int VIEWSTATE_LOADED = 1 << 13;
120 const int LOADED = 1 << 14;
121 const int PRERENDERED = 1 << 15;
123 const int ENABLE_THEMING = 1 << 16;
129 defaultNameArray = new string [100];
130 for (int i = 0 ; i < 100 ; i++)
131 defaultNameArray [i] = "_ctl" + i;
136 stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
137 if (this is INamingContainer)
138 stateMask |= IS_NAMING_CONTAINER;
143 protected ControlAdapter Adapter
146 // for the time being, fool the
147 // Control machinery into thinking we
148 // don't have an Adapter. This will
149 // allow us to write all the rest of
150 // the Adapter handling code without
151 // having to worry about *having*
157 [EditorBrowsable (EditorBrowsableState.Advanced)]
159 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
160 public string AppRelativeTemplateSourceDirectory
163 throw new NotImplementedException ();
165 [EditorBrowsable (EditorBrowsableState.Never)]
167 throw new NotImplementedException ();
173 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
174 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
175 public Control BindingContainer {
177 Control container = NamingContainer;
178 if ((container.stateMask & BINDING_CONTAINER) == 0)
179 container = container.BindingContainer;
184 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
186 [WebSysDescription ("An Identification of the control that is rendered.")]
187 public virtual string ClientID {
189 string client = UniqueID;
192 client = client.Replace (':', '_');
199 protected char ClientIDSeparator
202 throw new NotImplementedException ();
207 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
209 [WebSysDescription ("The child controls of this control.")]
210 public virtual ControlCollection Controls //DIT
214 if (_controls == null) _controls = CreateControlCollection();
220 protected internal bool DesignMode
223 throw new NotImplementedException ();
228 [DefaultValue (true), WebCategory ("Behavior")]
229 [WebSysDescription ("An Identification of the control that is rendered.")]
233 public virtual bool EnableViewState {
234 get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
235 set { SetMask (ENABLE_VIEWSTATE, value); }
238 [MergableProperty (false), ParenthesizePropertyName (true)]
239 [WebSysDescription ("The name of the control that is rendered.")]
241 [Filterable (false), Themeable (false)]
244 public virtual string ID {
246 return (((stateMask & ID_SET) != 0) ? _userId : null);
260 protected char IdSeparator
263 throw new NotImplementedException ();
267 protected internal bool IsChildControlStateCleared
270 throw new NotImplementedException ();
274 protected internal bool IsViewStateEnabled
277 throw new NotImplementedException ();
281 protected bool LoadViewStateByID
284 throw new NotImplementedException ();
289 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
291 [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
292 public virtual Control NamingContainer {
294 if (_namingContainer == null && _parent != null) {
295 if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
296 _namingContainer = _parent.NamingContainer;
298 _namingContainer = _parent;
301 return _namingContainer;
305 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
307 [WebSysDescription ("The webpage that this control resides on.")]
311 public virtual Page Page //DIT
315 if (_page == null && _parent != null) _page = _parent.Page;
324 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
326 [WebSysDescription ("The parent control of this control.")]
327 public virtual Control Parent //DIT
335 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
336 [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
337 [WebSysDescription ("The site this control is part of.")]
338 public ISite Site //DIT
352 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
353 public TemplateControl TemplateControl
356 throw new NotImplementedException ();
358 [EditorBrowsable (EditorBrowsableState.Never)]
360 throw new NotImplementedException ();
365 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
367 [WebSysDescription ("A virtual directory containing the parent of the control.")]
368 public virtual string TemplateSourceDirectory {
369 get { return (_parent == null) ? String.Empty : _parent.TemplateSourceDirectory; }
372 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
374 [WebSysDescription ("The unique ID of the control.")]
375 public virtual string UniqueID {
377 if (uniqueID != null)
380 if (_namingContainer == null) {
381 if ((stateMask & IS_NAMING_CONTAINER) == 0)
382 _namingContainer = NamingContainer;
383 if (_namingContainer == null)
388 _userId = _namingContainer.GetDefaultName ();
390 string prefix = _namingContainer.UniqueID;
391 if (_namingContainer == _page || prefix == null) {
396 uniqueID = prefix + ":" + _userId;
401 void SetMask (int m, bool val)
409 [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
410 [WebSysDescription ("Visiblity state of the control.")]
411 public virtual bool Visible {
413 if ((stateMask & VISIBLE) == 0)
417 return _parent.Visible;
423 if ((value && (stateMask & VISIBLE) == 0) ||
424 (!value && (stateMask & VISIBLE) != 0)) {
425 if (IsTrackingViewState)
426 stateMask |= VISIBLE_CHANGED;
429 SetMask (VISIBLE, value);
433 protected bool ChildControlsCreated {
434 get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
436 if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0)
439 SetMask (CHILD_CONTROLS_CREATED, value);
444 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
445 protected virtual HttpContext Context //DIT
450 if (_context != null)
453 return HttpContext.Current;
454 context = _parent.Context;
457 return HttpContext.Current;
461 protected EventHandlerList Events {
464 _events = new EventHandlerList ();
469 protected bool HasChildViewState {
471 return (pendingVS != null && pendingVS.Count > 0);
475 protected bool IsTrackingViewState {
476 get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
480 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
481 [WebSysDescription ("ViewState")]
482 protected virtual StateBag ViewState
486 if(_viewState == null)
487 _viewState = new StateBag (ViewStateIgnoresCase);
489 if (IsTrackingViewState)
490 _viewState.TrackViewState ();
497 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
498 protected virtual bool ViewStateIgnoresCase
505 internal bool AutoEventWireup {
506 get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
507 set { SetMask (AUTO_EVENT_WIREUP, value); }
510 internal void SetBindingContainer (bool isBC)
512 SetMask (BINDING_CONTAINER, isBC);
515 internal void ResetChildNames ()
520 string GetDefaultName ()
523 if (defaultNumberID > 99) {
524 defaultName = "_ctl" + defaultNumberID++;
526 defaultName = defaultNameArray [defaultNumberID++];
531 void NullifyUniqueID ()
537 foreach (Control c in Controls)
538 c.NullifyUniqueID ();
541 protected internal virtual void AddedControl (Control control, int index)
543 /* Ensure the control don't have more than 1 parent */
544 if (control._parent != null)
545 control._parent.Controls.Remove (control);
547 control._parent = this;
548 control._page = _page;
549 Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
552 control._namingContainer = nc;
553 if (control.AutoID == true && control._userId == null)
554 control._userId = nc.GetDefaultName ();
557 if ((stateMask & (INITING | INITED)) != 0)
558 control.InitRecursive (nc);
560 if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
561 if (pendingVS != null) {
562 object vs = pendingVS [index];
564 pendingVS.Remove (index);
565 if (pendingVS.Count == 0)
568 control.LoadViewStateRecursive (vs);
573 if ((stateMask & LOADED) != 0)
574 control.LoadRecursive ();
576 if ((stateMask & PRERENDERED) != 0)
577 control.PreRenderRecursiveInternal ();
580 protected virtual void AddParsedSubObject(object obj) //DIT
582 Control c = obj as Control;
583 if (c != null) Controls.Add(c);
587 [EditorBrowsable (EditorBrowsableState.Advanced)]
588 public virtual void ApplyStyleSheetSkin (Page page)
590 throw new NotImplementedException ();
594 protected void BuildProfileTree(string parentId, bool calcViewState)
600 protected void ClearChildControlState ()
602 throw new NotImplementedException ();
605 protected void ClearChildState ()
607 throw new NotImplementedException ();
611 protected void ClearChildViewState ()
621 virtual void CreateChildControls() {} //DIT
623 protected virtual ControlCollection CreateControlCollection() //DIT
625 return new ControlCollection(this);
628 protected virtual void EnsureChildControls ()
630 if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
631 stateMask |= CREATING_CONTROLS;
634 Adapter.CreateChildControls ();
637 CreateChildControls();
638 ChildControlsCreated = true;
639 stateMask &= ~CREATING_CONTROLS;
644 protected void EnsureID ()
646 throw new NotImplementedException ();
649 protected bool HasEvents ()
651 throw new NotImplementedException ();
657 protected bool IsLiteralContent()
659 if (HasControls () && Controls.Count == 1 && (Controls [0] is LiteralControl))
665 [WebSysDescription ("")]
666 public virtual Control FindControl (string id)
668 return FindControl (id, 0);
671 Control LookForControlByName (string id)
676 Control result = null;
677 foreach (Control c in Controls) {
678 if (String.Compare (id, c._userId, true) == 0) {
679 if (result != null && result != c) {
680 throw new HttpException ("1 Found more than one control with ID '" + id + "'");
687 if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
688 Control child = c.LookForControlByName (id);
690 if (result != null && result != child)
691 throw new HttpException ("2 Found more than one control with ID '" + id + "'");
701 protected virtual Control FindControl (string id, int pathOffset)
703 EnsureChildControls ();
704 Control namingContainer = null;
705 if ((stateMask & IS_NAMING_CONTAINER) == 0) {
706 namingContainer = NamingContainer;
707 if (namingContainer == null)
710 return namingContainer.FindControl (id, pathOffset);
716 int colon = id.IndexOf (':', pathOffset);
718 return LookForControlByName (id.Substring (pathOffset));
720 string idfound = id.Substring (pathOffset, colon - pathOffset);
721 namingContainer = LookForControlByName (idfound);
722 if (namingContainer == null)
725 return namingContainer.FindControl (id, colon + 1);
728 protected virtual void LoadViewState(object savedState)
730 if (savedState != null) {
731 ViewState.LoadViewState (savedState);
732 object o = ViewState ["Visible"];
734 SetMask (VISIBLE, (bool) o);
735 stateMask |= VISIBLE_CHANGED;
740 [MonoTODO("Secure?")]
741 protected string MapPathSecure(string virtualPath)
743 string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
744 return Context.Request.MapPath (combined);
747 protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
750 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
751 string type_name = null;
753 type_name = GetType ().Name;
754 trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
760 protected virtual void OnDataBinding (EventArgs e)
762 if ((event_mask & databinding_mask) != 0) {
763 EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
766 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
767 string type_name = null;
769 type_name = GetType ().Name;
770 trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
783 virtual void OnInit (EventArgs e)
785 if ((event_mask & init_mask) != 0) {
786 EventHandler eh = (EventHandler)(_events [InitEvent]);
789 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
790 string type_name = null;
792 type_name = GetType ().Name;
793 trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
806 virtual void OnLoad (EventArgs e)
808 if ((event_mask & load_mask) != 0) {
809 EventHandler eh = (EventHandler)(_events [LoadEvent]);
812 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
813 string type_name = null;
815 type_name = GetType ().Name;
816 trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
829 virtual void OnPreRender (EventArgs e)
831 if ((event_mask & prerender_mask) != 0) {
832 EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
835 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
836 string type_name = null;
838 type_name = GetType ().Name;
839 trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
852 virtual void OnUnload(EventArgs e)
854 if ((event_mask & unload_mask) != 0) {
855 EventHandler eh = (EventHandler)(_events [UnloadEvent]);
858 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
859 string type_name = null;
861 type_name = GetType ().Name;
862 trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
871 protected internal Stream OpenFile (string path)
873 throw new NotImplementedException ();
877 protected void RaiseBubbleEvent(object source, EventArgs args)
882 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
883 string type_name = null;
885 type_name = GetType ().Name;
886 trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
889 if (c.OnBubbleEvent (source, args)) {
892 trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
898 trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
909 virtual void Render(HtmlTextWriter writer) //DIT
911 RenderChildren(writer);
919 virtual void RenderChildren (HtmlTextWriter writer) //DIT
921 if (_renderMethodDelegate != null) {
922 _renderMethodDelegate (writer, this);
923 } else if (HasControls ()) {
924 int len = Controls.Count;
925 for (int i = 0; i < len; i++) {
926 Control c = Controls [i];
928 if (c.Adapter != null)
929 c.RenderControl (writer, c.Adapter);
932 c.RenderControl (writer);
938 protected virtual ControlAdapter ResolveAdapter ()
940 throw new NotImplementedException ();
944 protected virtual object SaveViewState ()
946 if ((stateMask & VISIBLE_CHANGED) != 0) {
947 ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
948 } else if (_viewState == null) {
952 return _viewState.SaveViewState ();
955 protected virtual void TrackViewState()
957 if (_viewState != null)
958 _viewState.TrackViewState ();
960 stateMask |= TRACK_VIEWSTATE;
963 public virtual void Dispose ()
965 if ((event_mask & disposed_mask) != 0) {
966 EventHandler eh = (EventHandler)(_events [DisposedEvent]);
967 if (eh != null) eh (this, EventArgs.Empty);
971 [WebCategory ("FIXME")]
972 [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
973 public event EventHandler DataBinding {
975 event_mask |= databinding_mask;
976 Events.AddHandler (DataBindingEvent, value);
978 remove { Events.RemoveHandler (DataBindingEvent, value); }
981 [WebSysDescription ("Raised when the contol is disposed.")]
982 public event EventHandler Disposed {
984 event_mask |= disposed_mask;
985 Events.AddHandler (DisposedEvent, value);
987 remove { Events.RemoveHandler (DisposedEvent, value); }
990 [WebSysDescription ("Raised when the page containing the control is initialized.")]
991 public event EventHandler Init {
993 event_mask |= init_mask;
994 Events.AddHandler (InitEvent, value);
996 remove { Events.RemoveHandler (InitEvent, value); }
999 [WebSysDescription ("Raised after the page containing the control has been loaded.")]
1000 public event EventHandler Load {
1002 event_mask |= load_mask;
1003 Events.AddHandler (LoadEvent, value);
1005 remove { Events.RemoveHandler (LoadEvent, value); }
1008 [WebSysDescription ("Raised before the page containing the control is rendered.")]
1009 public event EventHandler PreRender {
1011 event_mask |= prerender_mask;
1012 Events.AddHandler (PreRenderEvent, value);
1014 remove { Events.RemoveHandler (PreRenderEvent, value); }
1017 [WebSysDescription ("Raised when the page containing the control is unloaded.")]
1018 public event EventHandler Unload {
1020 event_mask |= unload_mask;
1021 Events.AddHandler (UnloadEvent, value);
1023 remove { Events.RemoveHandler (UnloadEvent, value); }
1026 public virtual void DataBind() //DIT
1031 OnDataBinding (EventArgs.Empty);
1040 void DataBindChildren ()
1042 if (!HasControls ())
1045 int len = Controls.Count;
1046 for (int i = 0; i < len; i++) {
1047 Control c = Controls [i];
1053 public virtual bool HasControls ()
1055 return (_controls != null && _controls.Count > 0);
1063 void RenderControl (HtmlTextWriter writer)
1065 if ((stateMask & VISIBLE) != 0) {
1066 HttpContext ctx = Context;
1067 TraceContext trace = (ctx != null) ? ctx.Trace : null;
1069 if (trace.IsEnabled)
1070 pos = ctx.Response.GetOutputByteCount ();
1073 if (trace.IsEnabled) {
1074 int size = ctx.Response.GetOutputByteCount () - pos;
1075 trace.SaveSize (this, size >= 0 ? size : 0);
1081 protected void RenderControl (HtmlTextWriter writer,
1082 ControlAdapter adapter)
1084 if ((stateMask & VISIBLE) != 0) {
1085 adapter.BeginRender (writer);
1086 adapter.Render (writer);
1087 adapter.EndRender (writer);
1092 public string ResolveUrl (string relativeUrl)
1094 if (relativeUrl == null)
1095 throw new ArgumentNullException ("relativeUrl");
1097 if (relativeUrl == "")
1100 if (relativeUrl [0] == '#')
1103 string ts = TemplateSourceDirectory;
1104 if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
1107 HttpResponse resp = Context.Response;
1108 return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
1111 internal bool HasRenderMethodDelegate () {
1112 return _renderMethodDelegate != null;
1115 [EditorBrowsable (EditorBrowsableState.Advanced)]
1116 public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
1118 _renderMethodDelegate = renderMethod;
1121 internal void LoadRecursive()
1124 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1125 string type_name = null;
1126 if (trace != null) {
1127 type_name = GetType ().Name;
1128 trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
1132 if (Adapter != null)
1133 Adapter.OnLoad (EventArgs.Empty);
1136 OnLoad (EventArgs.Empty);
1137 if (HasControls ()) {
1138 int len = Controls.Count;
1139 for (int i=0;i<len;i++)
1141 Control c = Controls[i];
1148 trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
1150 stateMask |= LOADED;
1153 internal void UnloadRecursive(Boolean dispose)
1156 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1157 string type_name = null;
1158 if (trace != null) {
1159 type_name = GetType ().Name;
1160 trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
1163 if (HasControls ()) {
1164 int len = Controls.Count;
1165 for (int i=0;i<len;i++)
1167 Control c = Controls[i];
1168 c.UnloadRecursive (dispose);
1174 trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
1177 if (Adapter != null)
1178 Adapter.OnUnload (EventArgs.Empty);
1181 OnUnload (EventArgs.Empty);
1186 internal void PreRenderRecursiveInternal()
1188 if ((stateMask & VISIBLE) != 0) {
1189 EnsureChildControls ();
1191 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1192 string type_name = null;
1193 if (trace != null) {
1194 type_name = GetType ().Name;
1195 trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
1199 if (Adapter != null)
1200 Adapter.OnPreRender (EventArgs.Empty);
1203 OnPreRender (EventArgs.Empty);
1204 if (!HasControls ())
1207 int len = Controls.Count;
1208 for (int i=0;i<len;i++)
1210 Control c = Controls[i];
1211 c.PreRenderRecursiveInternal ();
1215 trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
1218 stateMask |= PRERENDERED;
1221 internal void InitRecursive(Control namingContainer)
1224 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1225 string type_name = null;
1226 if (trace != null) {
1227 type_name = GetType ().Name;
1228 trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
1232 if (HasControls ()) {
1233 if ((stateMask & IS_NAMING_CONTAINER) != 0)
1234 namingContainer = this;
1236 if (namingContainer != null &&
1237 namingContainer._userId == null &&
1238 namingContainer.AutoID)
1239 namingContainer._userId = namingContainer.GetDefaultName () + "b";
1241 int len = Controls.Count;
1242 for (int i=0;i<len;i++)
1244 Control c = Controls[i];
1246 c._namingContainer = namingContainer;
1247 if (namingContainer != null && c._userId == null && c.AutoID)
1248 c._userId = namingContainer.GetDefaultName () + "c";
1249 c.InitRecursive (namingContainer);
1253 stateMask |= INITING;
1255 if (Adapter != null)
1256 Adapter.OnInit (EventArgs.Empty);
1259 OnInit (EventArgs.Empty);
1262 trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
1265 stateMask |= INITED;
1266 stateMask &= ~INITING;
1269 internal object SaveViewStateRecursive ()
1271 if (!EnableViewState)
1275 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1276 string type_name = null;
1277 if (trace != null) {
1278 type_name = GetType ().Name;
1279 trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
1283 ArrayList controlList = null;
1284 ArrayList controlStates = null;
1289 int len = Controls.Count;
1290 for (int i=0;i<len;i++)
1292 Control ctrl = Controls[i];
1293 object ctrlState = ctrl.SaveViewStateRecursive ();
1295 if (ctrlState == null)
1298 if (controlList == null)
1300 controlList = new ArrayList ();
1301 controlStates = new ArrayList ();
1304 controlList.Add (idx);
1305 controlStates.Add (ctrlState);
1309 object thisState = SaveViewState ();
1310 if (thisState == null && controlList == null && controlStates == null) {
1312 if (trace != null) {
1313 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
1314 trace.SaveViewState (this, null);
1321 if (trace != null) {
1322 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
1323 trace.SaveViewState (this, thisState);
1326 return new Triplet (thisState, controlList, controlStates);
1329 internal void LoadViewStateRecursive (object savedState)
1331 if (!EnableViewState || savedState == null)
1335 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1336 string type_name = null;
1337 if (trace != null) {
1338 type_name = GetType ().Name;
1339 trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
1342 Triplet savedInfo = (Triplet) savedState;
1343 LoadViewState (savedInfo.First);
1345 ArrayList controlList = savedInfo.Second as ArrayList;
1346 if (controlList == null)
1348 ArrayList controlStates = savedInfo.Third as ArrayList;
1349 int nControls = controlList.Count;
1350 for (int i = 0; i < nControls; i++) {
1351 int k = (int) controlList [i];
1352 if (k < Controls.Count && controlStates != null) {
1353 Control c = Controls [k];
1354 c.LoadViewStateRecursive (controlStates [i]);
1356 if (pendingVS == null)
1357 pendingVS = new Hashtable ();
1359 pendingVS [k] = controlStates [i];
1365 trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
1367 stateMask |= VIEWSTATE_LOADED;
1370 internal bool AutoID
1372 get { return (stateMask & AUTOID) != 0; }
1374 if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
1377 SetMask (AUTOID, value);
1381 protected internal virtual void RemovedControl (Control control)
1383 control.UnloadRecursive (false);
1384 control._parent = null;
1385 control._page = null;
1386 control._namingContainer = null;
1392 string skinId = string.Empty;
1396 [DefaultValue (true)]
1397 public virtual bool EnableTheming
1399 get { return (stateMask & ENABLE_THEMING) != 0; }
1400 set { SetMask (ENABLE_THEMING, value); }
1405 [Filterable (false)]
1406 public virtual string SkinID
1408 get { return skinId; }
1409 set { skinId = value; }
1412 /* This shouldnt be in 2.0, and I can't find it in 1.1
1413 * either, so leaving alone for now.
1415 protected string GetWebResourceUrl (string resourceName)
1417 return Page.ClientScript.GetWebResourceUrl (GetType(), resourceName);
1420 string IUrlResolutionService.ResolveClientUrl (string url)
1422 throw new NotImplementedException ();
1425 ControlBuilder IControlBuilderAccessor.ControlBuilder {
1426 get {throw new NotImplementedException (); }
1429 IDictionary IControlDesignerAccessor.GetDesignModeState ()
1431 throw new NotImplementedException ();
1434 void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
1436 SetDesignModeState (designData);
1439 void IControlDesignerAccessor.SetOwnerControl (Control control)
1441 throw new NotImplementedException ();
1444 IDictionary IControlDesignerAccessor.UserData {
1445 get { throw new NotImplementedException (); }
1448 ExpressionBindingCollection expressionBindings;
1450 ExpressionBindingCollection IExpressionsAccessor.Expressions {
1452 if (expressionBindings == null)
1453 expressionBindings = new ExpressionBindingCollection ();
1454 return expressionBindings;
1458 bool IExpressionsAccessor.HasExpressions {
1460 return (expressionBindings != null && expressionBindings.Count > 0);
1465 public virtual void Focus()
1467 throw new NotImplementedException();
1470 protected internal virtual void LoadControlState (object state)
1474 protected internal virtual object SaveControlState ()
1479 protected virtual void DataBind (bool raiseOnDataBinding)
1481 bool foundDataItem = false;
1483 if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
1484 object o = DataBinder.GetDataItem (this, out foundDataItem);
1486 Page.PushDataItemContext (o);
1491 if (raiseOnDataBinding)
1492 OnDataBinding (EventArgs.Empty);
1497 Page.PopDataItemContext ();
1501 protected virtual IDictionary GetDesignModeState ()
1503 throw new NotImplementedException ();
1506 protected virtual void SetDesignModeState (IDictionary data)
1508 throw new NotImplementedException ();
1511 void IParserAccessor.AddParsedSubObject (object obj) {
1512 this.AddParsedSubObject (obj);
1515 DataBindingCollection IDataBindingsAccessor.DataBindings {
1517 if (dataBindings == null) {
1518 dataBindings = new DataBindingCollection ();
1520 return dataBindings;
1524 bool IDataBindingsAccessor.HasDataBindings {
1526 if (dataBindings != null && dataBindings.Count > 0) {