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 TemplateControl _templateControl;
94 ControlCollection _controls;
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 string _appRelativeTemplateSourceDirectory = "~/";
164 [EditorBrowsable (EditorBrowsableState.Advanced)]
166 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
167 public string AppRelativeTemplateSourceDirectory
169 get { return _appRelativeTemplateSourceDirectory; }
170 [EditorBrowsable (EditorBrowsableState.Never)]
171 set { _appRelativeTemplateSourceDirectory = value; }
176 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
177 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
178 public Control BindingContainer {
180 Control container = NamingContainer;
181 if (container != null && (container.stateMask & BINDING_CONTAINER) == 0)
182 container = container.BindingContainer;
187 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
189 [WebSysDescription ("An Identification of the control that is rendered.")]
190 public virtual string ClientID {
192 string client = UniqueID;
195 client = client.Replace (':', '_');
202 protected char ClientIDSeparator
205 throw new NotImplementedException ();
210 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
212 [WebSysDescription ("The child controls of this control.")]
213 public virtual ControlCollection Controls //DIT
217 if (_controls == null) _controls = CreateControlCollection();
223 [MonoTODO ("revisit once we have a real design strategy")]
224 protected internal bool DesignMode
226 get { return false; }
230 [DefaultValue (true), WebCategory ("Behavior")]
231 [WebSysDescription ("An Identification of the control that is rendered.")]
235 public virtual bool EnableViewState {
236 get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
237 set { SetMask (ENABLE_VIEWSTATE, value); }
240 [MergableProperty (false), ParenthesizePropertyName (true)]
241 [WebSysDescription ("The name of the control that is rendered.")]
243 [Filterable (false), Themeable (false)]
246 public virtual string ID {
248 return (((stateMask & ID_SET) != 0) ? _userId : null);
262 protected char IdSeparator
265 throw new NotImplementedException ();
269 protected internal bool IsChildControlStateCleared
272 throw new NotImplementedException ();
276 protected internal bool IsViewStateEnabled
282 for (Control control = this; control != null; control = control.Parent)
283 if (!control.EnableViewState)
290 protected bool LoadViewStateByID
293 throw new NotImplementedException ();
298 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
300 [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
301 public virtual Control NamingContainer {
303 if (_namingContainer == null && _parent != null) {
304 if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
305 _namingContainer = _parent.NamingContainer;
307 _namingContainer = _parent;
310 return _namingContainer;
314 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
316 [WebSysDescription ("The webpage that this control resides on.")]
320 public virtual Page Page //DIT
324 if (_page == null && _parent != null) _page = _parent.Page;
333 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
335 [WebSysDescription ("The parent control of this control.")]
336 public virtual Control Parent //DIT
344 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
345 [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
346 [WebSysDescription ("The site this control is part of.")]
347 public ISite Site //DIT
361 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
362 public TemplateControl TemplateControl
365 return _templateControl;
367 [EditorBrowsable (EditorBrowsableState.Never)]
369 _templateControl = value;
374 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
376 [WebSysDescription ("A virtual directory containing the parent of the control.")]
377 public virtual string TemplateSourceDirectory {
378 get { return (_parent == null) ? String.Empty : _parent.TemplateSourceDirectory; }
381 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
383 [WebSysDescription ("The unique ID of the control.")]
384 public virtual string UniqueID {
386 if (uniqueID != null)
389 if (_namingContainer == null) {
390 if ((stateMask & IS_NAMING_CONTAINER) == 0)
391 _namingContainer = NamingContainer;
392 if (_namingContainer == null)
397 _userId = _namingContainer.GetDefaultName ();
399 string prefix = _namingContainer.UniqueID;
400 if (_namingContainer == _page || prefix == null) {
405 uniqueID = prefix + ":" + _userId;
410 void SetMask (int m, bool val)
418 [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
419 [WebSysDescription ("Visiblity state of the control.")]
420 public virtual bool Visible {
422 if ((stateMask & VISIBLE) == 0)
426 return _parent.Visible;
432 if ((value && (stateMask & VISIBLE) == 0) ||
433 (!value && (stateMask & VISIBLE) != 0)) {
434 if (IsTrackingViewState)
435 stateMask |= VISIBLE_CHANGED;
438 SetMask (VISIBLE, value);
442 protected bool ChildControlsCreated {
443 get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
445 if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0) {
446 if (_controls != null)
450 SetMask (CHILD_CONTROLS_CREATED, value);
455 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
456 protected virtual HttpContext Context //DIT
461 if (_context != null)
464 return HttpContext.Current;
465 context = _parent.Context;
468 return HttpContext.Current;
472 protected EventHandlerList Events {
475 _events = new EventHandlerList ();
480 protected bool HasChildViewState {
482 return (pendingVS != null && pendingVS.Count > 0);
486 protected bool IsTrackingViewState {
487 get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
491 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
492 [WebSysDescription ("ViewState")]
493 protected virtual StateBag ViewState
497 if(_viewState == null)
498 _viewState = new StateBag (ViewStateIgnoresCase);
500 if (IsTrackingViewState)
501 _viewState.TrackViewState ();
508 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
509 protected virtual bool ViewStateIgnoresCase
516 internal bool AutoEventWireup {
517 get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
518 set { SetMask (AUTO_EVENT_WIREUP, value); }
521 internal void SetBindingContainer (bool isBC)
523 SetMask (BINDING_CONTAINER, isBC);
526 internal void ResetChildNames ()
531 string GetDefaultName ()
534 if (defaultNumberID > 99) {
535 defaultName = "_ctl" + defaultNumberID++;
537 defaultName = defaultNameArray [defaultNumberID++];
542 void NullifyUniqueID ()
548 foreach (Control c in _controls)
549 c.NullifyUniqueID ();
552 protected internal virtual void AddedControl (Control control, int index)
554 /* Ensure the control don't have more than 1 parent */
555 if (control._parent != null)
556 control._parent.Controls.Remove (control);
558 control._parent = this;
559 control._page = _page;
560 Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
563 control._namingContainer = nc;
564 if (control.AutoID == true && control._userId == null)
565 control._userId = nc.GetDefaultName ();
568 if ((stateMask & (INITING | INITED)) != 0)
569 control.InitRecursive (nc);
571 if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
572 if (pendingVS != null) {
573 object vs = pendingVS [index];
575 pendingVS.Remove (index);
576 if (pendingVS.Count == 0)
579 control.LoadViewStateRecursive (vs);
584 if ((stateMask & LOADED) != 0)
585 control.LoadRecursive ();
587 if ((stateMask & PRERENDERED) != 0)
588 control.PreRenderRecursiveInternal ();
591 protected virtual void AddParsedSubObject(object obj) //DIT
593 Control c = obj as Control;
594 if (c != null) Controls.Add(c);
599 [EditorBrowsable (EditorBrowsableState.Advanced)]
600 public virtual void ApplyStyleSheetSkin (Page page)
602 if (!EnableTheming) /* this enough? */
605 /* apply the style sheet skin here */
606 if (page.StyleSheetPageTheme != null) {
607 ControlSkin cs = page.StyleSheetPageTheme.GetControlSkin (GetType(), SkinID);
614 protected void BuildProfileTree(string parentId, bool calcViewState)
620 protected void ClearChildControlState ()
622 throw new NotImplementedException ();
625 protected void ClearChildState ()
627 throw new NotImplementedException ();
631 protected void ClearChildViewState ()
641 virtual void CreateChildControls() {} //DIT
643 protected virtual ControlCollection CreateControlCollection() //DIT
645 return new ControlCollection(this);
648 protected virtual void EnsureChildControls ()
650 if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
651 stateMask |= CREATING_CONTROLS;
654 Adapter.CreateChildControls ();
657 CreateChildControls();
658 ChildControlsCreated = true;
659 stateMask &= ~CREATING_CONTROLS;
664 protected void EnsureID ()
666 throw new NotImplementedException ();
669 protected bool HasEvents ()
671 throw new NotImplementedException ();
677 protected bool IsLiteralContent()
679 if (HasControls () && _controls.Count == 1 && (_controls [0] is LiteralControl))
685 [WebSysDescription ("")]
686 public virtual Control FindControl (string id)
688 return FindControl (id, 0);
691 Control LookForControlByName (string id)
696 Control result = null;
697 foreach (Control c in _controls) {
698 if (String.Compare (id, c._userId, true) == 0) {
699 if (result != null && result != c) {
700 throw new HttpException ("1 Found more than one control with ID '" + id + "'");
707 if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
708 Control child = c.LookForControlByName (id);
710 if (result != null && result != child)
711 throw new HttpException ("2 Found more than one control with ID '" + id + "'");
721 protected virtual Control FindControl (string id, int pathOffset)
723 EnsureChildControls ();
724 Control namingContainer = null;
725 if ((stateMask & IS_NAMING_CONTAINER) == 0) {
726 namingContainer = NamingContainer;
727 if (namingContainer == null)
730 return namingContainer.FindControl (id, pathOffset);
736 int colon = id.IndexOf (':', pathOffset);
738 return LookForControlByName (id.Substring (pathOffset));
740 string idfound = id.Substring (pathOffset, colon - pathOffset);
741 namingContainer = LookForControlByName (idfound);
742 if (namingContainer == null)
745 return namingContainer.FindControl (id, colon + 1);
748 protected virtual void LoadViewState(object savedState)
750 if (savedState != null) {
751 ViewState.LoadViewState (savedState);
752 object o = ViewState ["Visible"];
754 SetMask (VISIBLE, (bool) o);
755 stateMask |= VISIBLE_CHANGED;
760 [MonoTODO("Secure?")]
761 protected string MapPathSecure(string virtualPath)
763 string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
764 return Context.Request.MapPath (combined);
767 protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
770 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
771 string type_name = null;
773 type_name = GetType ().Name;
774 trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
780 protected virtual void OnDataBinding (EventArgs e)
782 if ((event_mask & databinding_mask) != 0) {
783 EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
786 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
787 string type_name = null;
789 type_name = GetType ().Name;
790 trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
803 virtual void OnInit (EventArgs e)
805 if ((event_mask & init_mask) != 0) {
806 EventHandler eh = (EventHandler)(_events [InitEvent]);
809 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
810 string type_name = null;
812 type_name = GetType ().Name;
813 trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
826 virtual void OnLoad (EventArgs e)
828 if ((event_mask & load_mask) != 0) {
829 EventHandler eh = (EventHandler)(_events [LoadEvent]);
832 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
833 string type_name = null;
835 type_name = GetType ().Name;
836 trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
849 virtual void OnPreRender (EventArgs e)
851 if ((event_mask & prerender_mask) != 0) {
852 EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
855 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
856 string type_name = null;
858 type_name = GetType ().Name;
859 trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
872 virtual void OnUnload(EventArgs e)
874 if ((event_mask & unload_mask) != 0) {
875 EventHandler eh = (EventHandler)(_events [UnloadEvent]);
878 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
879 string type_name = null;
881 type_name = GetType ().Name;
882 trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
891 protected internal Stream OpenFile (string path)
893 throw new NotImplementedException ();
897 protected void RaiseBubbleEvent(object source, EventArgs args)
902 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
903 string type_name = null;
905 type_name = GetType ().Name;
906 trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
909 if (c.OnBubbleEvent (source, args)) {
912 trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
918 trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
929 virtual void Render(HtmlTextWriter writer) //DIT
931 RenderChildren(writer);
939 virtual void RenderChildren (HtmlTextWriter writer) //DIT
941 if (_renderMethodDelegate != null) {
942 _renderMethodDelegate (writer, this);
943 } else if (_controls != null) {
944 int len = _controls.Count;
945 for (int i = 0; i < len; i++) {
946 Control c = _controls [i];
948 if (c.Adapter != null)
949 c.RenderControl (writer, c.Adapter);
952 c.RenderControl (writer);
958 protected virtual ControlAdapter ResolveAdapter ()
960 throw new NotImplementedException ();
964 protected virtual object SaveViewState ()
966 if ((stateMask & VISIBLE_CHANGED) != 0) {
967 ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
968 } else if (_viewState == null) {
972 return _viewState.SaveViewState ();
975 protected virtual void TrackViewState()
977 if (_viewState != null)
978 _viewState.TrackViewState ();
980 stateMask |= TRACK_VIEWSTATE;
983 public virtual void Dispose ()
985 if ((event_mask & disposed_mask) != 0) {
986 EventHandler eh = (EventHandler)(_events [DisposedEvent]);
987 if (eh != null) eh (this, EventArgs.Empty);
991 [WebCategory ("FIXME")]
992 [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
993 public event EventHandler DataBinding {
995 event_mask |= databinding_mask;
996 Events.AddHandler (DataBindingEvent, value);
998 remove { Events.RemoveHandler (DataBindingEvent, value); }
1001 [WebSysDescription ("Raised when the contol is disposed.")]
1002 public event EventHandler Disposed {
1004 event_mask |= disposed_mask;
1005 Events.AddHandler (DisposedEvent, value);
1007 remove { Events.RemoveHandler (DisposedEvent, value); }
1010 [WebSysDescription ("Raised when the page containing the control is initialized.")]
1011 public event EventHandler Init {
1013 event_mask |= init_mask;
1014 Events.AddHandler (InitEvent, value);
1016 remove { Events.RemoveHandler (InitEvent, value); }
1019 [WebSysDescription ("Raised after the page containing the control has been loaded.")]
1020 public event EventHandler Load {
1022 event_mask |= load_mask;
1023 Events.AddHandler (LoadEvent, value);
1025 remove { Events.RemoveHandler (LoadEvent, value); }
1028 [WebSysDescription ("Raised before the page containing the control is rendered.")]
1029 public event EventHandler PreRender {
1031 event_mask |= prerender_mask;
1032 Events.AddHandler (PreRenderEvent, value);
1034 remove { Events.RemoveHandler (PreRenderEvent, value); }
1037 [WebSysDescription ("Raised when the page containing the control is unloaded.")]
1038 public event EventHandler Unload {
1040 event_mask |= unload_mask;
1041 Events.AddHandler (UnloadEvent, value);
1043 remove { Events.RemoveHandler (UnloadEvent, value); }
1046 public virtual void DataBind() //DIT
1051 OnDataBinding (EventArgs.Empty);
1060 void DataBindChildren ()
1062 if (!HasControls ())
1065 int len = _controls.Count;
1066 for (int i = 0; i < len; i++) {
1067 Control c = _controls [i];
1073 public virtual bool HasControls ()
1075 return (_controls != null && _controls.Count > 0);
1083 void RenderControl (HtmlTextWriter writer)
1085 if ((stateMask & VISIBLE) != 0) {
1086 HttpContext ctx = Context;
1087 TraceContext trace = (ctx != null) ? ctx.Trace : null;
1089 if ((trace != null) && trace.IsEnabled)
1090 pos = ctx.Response.GetOutputByteCount ();
1093 if ((trace != null) && trace.IsEnabled) {
1094 int size = ctx.Response.GetOutputByteCount () - pos;
1095 trace.SaveSize (this, size >= 0 ? size : 0);
1101 protected void RenderControl (HtmlTextWriter writer,
1102 ControlAdapter adapter)
1104 if ((stateMask & VISIBLE) != 0) {
1105 adapter.BeginRender (writer);
1106 adapter.Render (writer);
1107 adapter.EndRender (writer);
1112 public string ResolveUrl (string relativeUrl)
1114 if (relativeUrl == null)
1115 throw new ArgumentNullException ("relativeUrl");
1117 if (relativeUrl == "")
1120 if (relativeUrl [0] == '#')
1123 string ts = TemplateSourceDirectory;
1124 if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
1127 HttpResponse resp = Context.Response;
1128 return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
1137 string ResolveClientUrl (string relativeUrl)
1139 if (relativeUrl == null)
1140 throw new ArgumentNullException ("relativeUrl");
1142 if (relativeUrl == "")
1145 if (relativeUrl [0] == '#')
1148 string ts = TemplateSourceDirectory;
1149 if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
1152 HttpResponse resp = Context.Response;
1153 string absoluteUrl = resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
1154 if (absoluteUrl.StartsWith (ts + "/"))
1155 return absoluteUrl.Substring (ts.Length + 1);
1159 internal bool HasRenderMethodDelegate () {
1160 return _renderMethodDelegate != null;
1163 [EditorBrowsable (EditorBrowsableState.Advanced)]
1164 public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
1166 _renderMethodDelegate = renderMethod;
1169 internal void LoadRecursive()
1172 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1173 string type_name = null;
1174 if (trace != null) {
1175 type_name = GetType ().Name;
1176 trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
1180 if (Adapter != null)
1181 Adapter.OnLoad (EventArgs.Empty);
1184 OnLoad (EventArgs.Empty);
1185 if (HasControls ()) {
1186 int len = _controls.Count;
1187 for (int i=0;i<len;i++)
1189 Control c = _controls[i];
1196 trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
1198 stateMask |= LOADED;
1201 internal void UnloadRecursive(Boolean dispose)
1204 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1205 string type_name = null;
1206 if (trace != null) {
1207 type_name = GetType ().Name;
1208 trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
1211 if (HasControls ()) {
1212 int len = _controls.Count;
1213 for (int i=0;i<len;i++)
1215 Control c = _controls[i];
1216 c.UnloadRecursive (dispose);
1222 trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
1225 if (Adapter != null)
1226 Adapter.OnUnload (EventArgs.Empty);
1229 OnUnload (EventArgs.Empty);
1234 internal void PreRenderRecursiveInternal()
1236 if ((stateMask & VISIBLE) != 0) {
1237 EnsureChildControls ();
1239 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1240 string type_name = null;
1241 if (trace != null) {
1242 type_name = GetType ().Name;
1243 trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
1247 if (Adapter != null)
1248 Adapter.OnPreRender (EventArgs.Empty);
1251 OnPreRender (EventArgs.Empty);
1252 if (!HasControls ())
1255 int len = _controls.Count;
1256 for (int i=0;i<len;i++)
1258 Control c = _controls[i];
1259 c.PreRenderRecursiveInternal ();
1263 trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
1266 stateMask |= PRERENDERED;
1269 internal void InitRecursive(Control namingContainer)
1272 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1273 string type_name = null;
1274 if (trace != null) {
1275 type_name = GetType ().Name;
1276 trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
1279 if (HasControls ()) {
1280 if ((stateMask & IS_NAMING_CONTAINER) != 0)
1281 namingContainer = this;
1283 if (namingContainer != null &&
1284 namingContainer._userId == null &&
1285 namingContainer.AutoID)
1286 namingContainer._userId = namingContainer.GetDefaultName () + "b";
1288 int len = _controls.Count;
1289 for (int i=0;i<len;i++)
1291 Control c = _controls[i];
1293 c._namingContainer = namingContainer;
1294 if (namingContainer != null && c._userId == null && c.AutoID)
1295 c._userId = namingContainer.GetDefaultName () + "c";
1296 c.InitRecursive (namingContainer);
1300 stateMask |= INITING;
1304 if (Adapter != null)
1305 Adapter.OnInit (EventArgs.Empty);
1308 OnInit (EventArgs.Empty);
1311 trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
1314 stateMask |= INITED;
1315 stateMask &= ~INITING;
1318 internal object SaveViewStateRecursive ()
1320 if (!EnableViewState)
1324 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1325 string type_name = null;
1326 if (trace != null) {
1327 type_name = GetType ().Name;
1328 trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
1332 ArrayList controlList = null;
1333 ArrayList controlStates = null;
1338 int len = _controls.Count;
1339 for (int i=0;i<len;i++)
1341 Control ctrl = _controls[i];
1342 object ctrlState = ctrl.SaveViewStateRecursive ();
1344 if (ctrlState == null)
1347 if (controlList == null)
1349 controlList = new ArrayList ();
1350 controlStates = new ArrayList ();
1353 controlList.Add (idx);
1354 controlStates.Add (ctrlState);
1358 object thisState = SaveViewState ();
1359 if (thisState == null && controlList == null && controlStates == null) {
1361 if (trace != null) {
1362 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
1363 trace.SaveViewState (this, null);
1370 if (trace != null) {
1371 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
1372 trace.SaveViewState (this, thisState);
1375 return new Triplet (thisState, controlList, controlStates);
1378 internal void LoadViewStateRecursive (object savedState)
1380 if (!EnableViewState || savedState == null)
1384 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1385 string type_name = null;
1386 if (trace != null) {
1387 type_name = GetType ().Name;
1388 trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
1391 Triplet savedInfo = (Triplet) savedState;
1392 LoadViewState (savedInfo.First);
1394 ArrayList controlList = savedInfo.Second as ArrayList;
1395 if (controlList == null)
1397 ArrayList controlStates = savedInfo.Third as ArrayList;
1398 int nControls = controlList.Count;
1399 for (int i = 0; i < nControls; i++) {
1400 int k = (int) controlList [i];
1401 if (k < Controls.Count && controlStates != null) {
1402 Control c = Controls [k];
1403 c.LoadViewStateRecursive (controlStates [i]);
1405 if (pendingVS == null)
1406 pendingVS = new Hashtable ();
1408 pendingVS [k] = controlStates [i];
1414 trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
1416 stateMask |= VIEWSTATE_LOADED;
1420 internal ControlSkin controlSkin;
1422 internal void ApplyTheme ()
1425 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1426 string type_name = null;
1427 if (trace != null) {
1428 type_name = GetType ().Name;
1429 trace.Write ("control", String.Format ("ApplyThemeRecursive {0} {1}", _userId, type_name));
1432 if (Page.PageTheme != null && EnableTheming) {
1433 ControlSkin controlSkin = Page.PageTheme.GetControlSkin (GetType (), SkinID);
1434 if (controlSkin != null)
1435 controlSkin.ApplySkin (this);
1440 trace.Write ("control", String.Format ("End ApplyThemeRecursive {0} {1}", _userId, type_name));
1445 internal bool AutoID
1447 get { return (stateMask & AUTOID) != 0; }
1449 if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
1452 SetMask (AUTOID, value);
1456 protected internal virtual void RemovedControl (Control control)
1458 control.UnloadRecursive (false);
1459 control._parent = null;
1460 control._page = null;
1461 control._namingContainer = null;
1467 string skinId = string.Empty;
1468 bool _enableTheming = true;
1472 [DefaultValue (true)]
1473 public virtual bool EnableTheming
1477 if ((stateMask & ENABLE_THEMING) != 0)
1478 return _enableTheming;
1480 if (_parent != null)
1481 return _parent.EnableTheming;
1487 SetMask (ENABLE_THEMING, true);
1488 _enableTheming = value;
1494 [Filterable (false)]
1495 public virtual string SkinID
1497 get { return skinId; }
1498 set { skinId = value; }
1501 ControlBuilder IControlBuilderAccessor.ControlBuilder {
1502 get {throw new NotImplementedException (); }
1505 IDictionary IControlDesignerAccessor.GetDesignModeState ()
1507 throw new NotImplementedException ();
1510 void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
1512 SetDesignModeState (designData);
1515 void IControlDesignerAccessor.SetOwnerControl (Control control)
1517 throw new NotImplementedException ();
1520 IDictionary IControlDesignerAccessor.UserData {
1521 get { throw new NotImplementedException (); }
1524 ExpressionBindingCollection expressionBindings;
1526 ExpressionBindingCollection IExpressionsAccessor.Expressions {
1528 if (expressionBindings == null)
1529 expressionBindings = new ExpressionBindingCollection ();
1530 return expressionBindings;
1534 bool IExpressionsAccessor.HasExpressions {
1536 return (expressionBindings != null && expressionBindings.Count > 0);
1541 public virtual void Focus()
1543 throw new NotImplementedException();
1546 protected internal virtual void LoadControlState (object state)
1550 protected internal virtual object SaveControlState ()
1555 protected virtual void DataBind (bool raiseOnDataBinding)
1557 bool foundDataItem = false;
1559 if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
1560 object o = DataBinder.GetDataItem (this, out foundDataItem);
1562 Page.PushDataItemContext (o);
1567 if (raiseOnDataBinding)
1568 OnDataBinding (EventArgs.Empty);
1573 Page.PopDataItemContext ();
1577 protected virtual IDictionary GetDesignModeState ()
1579 throw new NotImplementedException ();
1582 protected virtual void SetDesignModeState (IDictionary data)
1584 throw new NotImplementedException ();
1587 void IParserAccessor.AddParsedSubObject (object obj) {
1588 this.AddParsedSubObject (obj);
1591 DataBindingCollection IDataBindingsAccessor.DataBindings {
1593 if (dataBindings == null) {
1594 dataBindings = new DataBindingCollection ();
1596 return dataBindings;
1600 bool IDataBindingsAccessor.HasDataBindings {
1602 if (dataBindings != null && dataBindings.Count > 0) {