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 Control _namingContainer;
100 EventHandlerList _events;
101 RenderMethod _renderMethodDelegate;
104 DataBindingCollection dataBindings;
105 Hashtable pendingVS; // may hold unused viewstate data from child controls
110 const int ENABLE_VIEWSTATE = 1;
111 const int VISIBLE = 1 << 1;
112 const int AUTOID = 1 << 2;
113 const int CREATING_CONTROLS = 1 << 3;
114 const int BINDING_CONTAINER = 1 << 4;
115 const int AUTO_EVENT_WIREUP = 1 << 5;
116 const int IS_NAMING_CONTAINER = 1 << 6;
117 const int VISIBLE_CHANGED = 1 << 7;
118 const int TRACK_VIEWSTATE = 1 << 8;
119 const int CHILD_CONTROLS_CREATED = 1 << 9;
120 const int ID_SET = 1 << 10;
121 const int INITED = 1 << 11;
122 const int INITING = 1 << 12;
123 const int VIEWSTATE_LOADED = 1 << 13;
124 const int LOADED = 1 << 14;
125 const int PRERENDERED = 1 << 15;
127 const int ENABLE_THEMING = 1 << 16;
133 defaultNameArray = new string [100];
134 for (int i = 0 ; i < 100 ; i++)
135 defaultNameArray [i] = "_ctl" + i;
140 stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
141 if (this is INamingContainer)
142 stateMask |= IS_NAMING_CONTAINER;
147 protected ControlAdapter Adapter
150 // for the time being, fool the
151 // Control machinery into thinking we
152 // don't have an Adapter. This will
153 // allow us to write all the rest of
154 // the Adapter handling code without
155 // having to worry about *having*
161 [EditorBrowsable (EditorBrowsableState.Advanced)]
163 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
164 public string AppRelativeTemplateSourceDirectory
167 throw new NotImplementedException ();
169 [EditorBrowsable (EditorBrowsableState.Never)]
171 throw new NotImplementedException ();
177 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
178 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
179 public Control BindingContainer {
181 Control container = NamingContainer;
182 if ((container.stateMask & BINDING_CONTAINER) == 0)
183 container = container.BindingContainer;
188 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
190 [WebSysDescription ("An Identification of the control that is rendered.")]
191 public virtual string ClientID {
193 string client = UniqueID;
196 client = client.Replace (':', '_');
203 protected char ClientIDSeparator
206 throw new NotImplementedException ();
211 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
213 [WebSysDescription ("The child controls of this control.")]
214 public virtual ControlCollection Controls //DIT
218 if (_controls == null) _controls = CreateControlCollection();
224 protected internal bool DesignMode
227 throw new NotImplementedException ();
232 [DefaultValue (true), WebCategory ("Behavior")]
233 [WebSysDescription ("An Identification of the control that is rendered.")]
237 public virtual bool EnableViewState {
238 get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
239 set { SetMask (ENABLE_VIEWSTATE, value); }
242 [MergableProperty (false), ParenthesizePropertyName (true)]
243 [WebSysDescription ("The name of the control that is rendered.")]
245 [Filterable (false), Themeable (false)]
248 public virtual string ID {
250 return (((stateMask & ID_SET) != 0) ? _userId : null);
264 protected char IdSeparator
267 throw new NotImplementedException ();
271 protected internal bool IsChildControlStateCleared
274 throw new NotImplementedException ();
278 protected internal bool IsViewStateEnabled
281 throw new NotImplementedException ();
285 protected bool LoadViewStateByID
288 throw new NotImplementedException ();
293 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
295 [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
296 public virtual Control NamingContainer {
298 if (_namingContainer == null && _parent != null) {
299 if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
300 _namingContainer = _parent.NamingContainer;
302 _namingContainer = _parent;
305 return _namingContainer;
309 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
311 [WebSysDescription ("The webpage that this control resides on.")]
315 public virtual Page Page //DIT
319 if (_page == null && _parent != null) _page = _parent.Page;
328 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
330 [WebSysDescription ("The parent control of this control.")]
331 public virtual Control Parent //DIT
339 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
340 [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
341 [WebSysDescription ("The site this control is part of.")]
342 public ISite Site //DIT
356 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
357 public TemplateControl TemplateControl
360 throw new NotImplementedException ();
362 [EditorBrowsable (EditorBrowsableState.Never)]
364 throw new NotImplementedException ();
369 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
371 [WebSysDescription ("A virtual directory containing the parent of the control.")]
372 public virtual string TemplateSourceDirectory {
373 get { return (_parent == null) ? String.Empty : _parent.TemplateSourceDirectory; }
376 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
378 [WebSysDescription ("The unique ID of the control.")]
379 public virtual string UniqueID {
381 if (uniqueID != null)
384 if (_namingContainer == null) {
385 if ((stateMask & IS_NAMING_CONTAINER) == 0)
386 _namingContainer = NamingContainer;
387 if (_namingContainer == null)
392 _userId = _namingContainer.GetDefaultName ();
394 string prefix = _namingContainer.UniqueID;
395 if (_namingContainer == _page || prefix == null) {
400 uniqueID = prefix + ":" + _userId;
405 void SetMask (int m, bool val)
413 [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
414 [WebSysDescription ("Visiblity state of the control.")]
415 public virtual bool Visible {
417 if ((stateMask & VISIBLE) == 0)
421 return _parent.Visible;
427 if ((value && (stateMask & VISIBLE) == 0) ||
428 (!value && (stateMask & VISIBLE) != 0)) {
429 if (IsTrackingViewState)
430 stateMask |= VISIBLE_CHANGED;
433 SetMask (VISIBLE, value);
437 protected bool ChildControlsCreated {
438 get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
440 if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0)
443 SetMask (CHILD_CONTROLS_CREATED, value);
448 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
449 protected virtual HttpContext Context //DIT
454 if (_context != null)
457 return HttpContext.Current;
458 context = _parent.Context;
461 return HttpContext.Current;
465 protected EventHandlerList Events {
468 _events = new EventHandlerList ();
473 protected bool HasChildViewState {
475 return (pendingVS != null && pendingVS.Count > 0);
479 protected bool IsTrackingViewState {
480 get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
484 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
485 [WebSysDescription ("ViewState")]
486 protected virtual StateBag ViewState
490 if(_viewState == null)
491 _viewState = new StateBag (ViewStateIgnoresCase);
493 if (IsTrackingViewState)
494 _viewState.TrackViewState ();
501 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
502 protected virtual bool ViewStateIgnoresCase
509 internal bool AutoEventWireup {
510 get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
511 set { SetMask (AUTO_EVENT_WIREUP, value); }
514 internal void SetBindingContainer (bool isBC)
516 SetMask (BINDING_CONTAINER, isBC);
519 internal void ResetChildNames ()
524 string GetDefaultName ()
527 if (defaultNumberID > 99) {
528 defaultName = "_ctl" + defaultNumberID++;
530 defaultName = defaultNameArray [defaultNumberID++];
535 void NullifyUniqueID ()
541 foreach (Control c in Controls)
542 c.NullifyUniqueID ();
545 protected internal virtual void AddedControl (Control control, int index)
547 /* Ensure the control don't have more than 1 parent */
548 if (control._parent != null)
549 control._parent.Controls.Remove (control);
551 control._parent = this;
552 control._page = _page;
553 Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
556 control._namingContainer = nc;
557 if (control.AutoID == true && control._userId == null)
558 control._userId = nc.GetDefaultName ();
561 if ((stateMask & (INITING | INITED)) != 0)
562 control.InitRecursive (nc);
564 if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
565 if (pendingVS != null) {
566 object vs = pendingVS [index];
568 pendingVS.Remove (index);
569 if (pendingVS.Count == 0)
572 control.LoadViewStateRecursive (vs);
577 if ((stateMask & LOADED) != 0)
578 control.LoadRecursive ();
580 if ((stateMask & PRERENDERED) != 0)
581 control.PreRenderRecursiveInternal ();
584 protected virtual void AddParsedSubObject(object obj) //DIT
586 Control c = obj as Control;
587 if (c != null) Controls.Add(c);
591 [EditorBrowsable (EditorBrowsableState.Advanced)]
592 public virtual void ApplyStyleSheetSkin (Page page)
594 throw new NotImplementedException ();
598 protected void BuildProfileTree(string parentId, bool calcViewState)
604 protected void ClearChildControlState ()
606 throw new NotImplementedException ();
609 protected void ClearChildState ()
611 throw new NotImplementedException ();
615 protected void ClearChildViewState ()
625 virtual void CreateChildControls() {} //DIT
627 protected virtual ControlCollection CreateControlCollection() //DIT
629 return new ControlCollection(this);
632 protected virtual void EnsureChildControls ()
634 if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
635 stateMask |= CREATING_CONTROLS;
638 Adapter.CreateChildControls ();
641 CreateChildControls();
642 ChildControlsCreated = true;
643 stateMask &= ~CREATING_CONTROLS;
648 protected void EnsureID ()
650 throw new NotImplementedException ();
653 protected bool HasEvents ()
655 throw new NotImplementedException ();
661 protected bool IsLiteralContent()
663 if (HasControls () && Controls.Count == 1 && (Controls [0] is LiteralControl))
669 [WebSysDescription ("")]
670 public virtual Control FindControl (string id)
672 return FindControl (id, 0);
675 Control LookForControlByName (string id)
680 Control result = null;
681 foreach (Control c in Controls) {
682 if (String.Compare (id, c._userId, true) == 0) {
683 if (result != null && result != c) {
684 throw new HttpException ("1 Found more than one control with ID '" + id + "'");
691 if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
692 Control child = c.LookForControlByName (id);
694 if (result != null && result != child)
695 throw new HttpException ("2 Found more than one control with ID '" + id + "'");
705 protected virtual Control FindControl (string id, int pathOffset)
707 EnsureChildControls ();
708 Control namingContainer = null;
709 if ((stateMask & IS_NAMING_CONTAINER) == 0) {
710 namingContainer = NamingContainer;
711 if (namingContainer == null)
714 return namingContainer.FindControl (id, pathOffset);
720 int colon = id.IndexOf (':', pathOffset);
722 return LookForControlByName (id.Substring (pathOffset));
724 string idfound = id.Substring (pathOffset, colon - pathOffset);
725 namingContainer = LookForControlByName (idfound);
726 if (namingContainer == null)
729 return namingContainer.FindControl (id, colon + 1);
732 protected virtual void LoadViewState(object savedState)
734 if (savedState != null) {
735 ViewState.LoadViewState (savedState);
736 object o = ViewState ["Visible"];
738 SetMask (VISIBLE, (bool) o);
739 stateMask |= VISIBLE_CHANGED;
744 [MonoTODO("Secure?")]
745 protected string MapPathSecure(string virtualPath)
747 string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
748 return Context.Request.MapPath (combined);
751 protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
754 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
755 string type_name = null;
757 type_name = GetType ().Name;
758 trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
764 protected virtual void OnDataBinding (EventArgs e)
766 if ((event_mask & databinding_mask) != 0) {
767 EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
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 ("OnDataBinding {0} {1}", _userId, type_name));
787 virtual void OnInit (EventArgs e)
789 if ((event_mask & init_mask) != 0) {
790 EventHandler eh = (EventHandler)(_events [InitEvent]);
793 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
794 string type_name = null;
796 type_name = GetType ().Name;
797 trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
810 virtual void OnLoad (EventArgs e)
812 if ((event_mask & load_mask) != 0) {
813 EventHandler eh = (EventHandler)(_events [LoadEvent]);
816 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
817 string type_name = null;
819 type_name = GetType ().Name;
820 trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
833 virtual void OnPreRender (EventArgs e)
835 if ((event_mask & prerender_mask) != 0) {
836 EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
839 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
840 string type_name = null;
842 type_name = GetType ().Name;
843 trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
856 virtual void OnUnload(EventArgs e)
858 if ((event_mask & unload_mask) != 0) {
859 EventHandler eh = (EventHandler)(_events [UnloadEvent]);
862 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
863 string type_name = null;
865 type_name = GetType ().Name;
866 trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
875 protected internal Stream OpenFile (string path)
877 throw new NotImplementedException ();
881 protected void RaiseBubbleEvent(object source, EventArgs args)
886 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
887 string type_name = null;
889 type_name = GetType ().Name;
890 trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
893 if (c.OnBubbleEvent (source, args)) {
896 trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
902 trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
913 virtual void Render(HtmlTextWriter writer) //DIT
915 RenderChildren(writer);
923 virtual void RenderChildren (HtmlTextWriter writer) //DIT
925 if (_renderMethodDelegate != null) {
926 _renderMethodDelegate (writer, this);
927 } else if (HasControls ()) {
928 int len = Controls.Count;
929 for (int i = 0; i < len; i++) {
930 Control c = Controls [i];
932 if (c.Adapter != null)
933 c.RenderControl (writer, c.Adapter);
936 c.RenderControl (writer);
942 protected virtual ControlAdapter ResolveAdapter ()
944 throw new NotImplementedException ();
948 protected virtual object SaveViewState ()
950 if ((stateMask & VISIBLE_CHANGED) != 0) {
951 ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
952 } else if (_viewState == null) {
956 return _viewState.SaveViewState ();
959 protected virtual void TrackViewState()
961 if (_viewState != null)
962 _viewState.TrackViewState ();
964 stateMask |= TRACK_VIEWSTATE;
967 public virtual void Dispose ()
969 if ((event_mask & disposed_mask) != 0) {
970 EventHandler eh = (EventHandler)(_events [DisposedEvent]);
971 if (eh != null) eh (this, EventArgs.Empty);
975 [WebCategory ("FIXME")]
976 [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
977 public event EventHandler DataBinding {
979 event_mask |= databinding_mask;
980 Events.AddHandler (DataBindingEvent, value);
982 remove { Events.RemoveHandler (DataBindingEvent, value); }
985 [WebSysDescription ("Raised when the contol is disposed.")]
986 public event EventHandler Disposed {
988 event_mask |= disposed_mask;
989 Events.AddHandler (DisposedEvent, value);
991 remove { Events.RemoveHandler (DisposedEvent, value); }
994 [WebSysDescription ("Raised when the page containing the control is initialized.")]
995 public event EventHandler Init {
997 event_mask |= init_mask;
998 Events.AddHandler (InitEvent, value);
1000 remove { Events.RemoveHandler (InitEvent, value); }
1003 [WebSysDescription ("Raised after the page containing the control has been loaded.")]
1004 public event EventHandler Load {
1006 event_mask |= load_mask;
1007 Events.AddHandler (LoadEvent, value);
1009 remove { Events.RemoveHandler (LoadEvent, value); }
1012 [WebSysDescription ("Raised before the page containing the control is rendered.")]
1013 public event EventHandler PreRender {
1015 event_mask |= prerender_mask;
1016 Events.AddHandler (PreRenderEvent, value);
1018 remove { Events.RemoveHandler (PreRenderEvent, value); }
1021 [WebSysDescription ("Raised when the page containing the control is unloaded.")]
1022 public event EventHandler Unload {
1024 event_mask |= unload_mask;
1025 Events.AddHandler (UnloadEvent, value);
1027 remove { Events.RemoveHandler (UnloadEvent, value); }
1030 public virtual void DataBind() //DIT
1035 OnDataBinding (EventArgs.Empty);
1044 void DataBindChildren ()
1046 if (!HasControls ())
1049 int len = Controls.Count;
1050 for (int i = 0; i < len; i++) {
1051 Control c = Controls [i];
1057 public virtual bool HasControls ()
1059 return (_controls != null && _controls.Count > 0);
1067 void RenderControl (HtmlTextWriter writer)
1069 if ((stateMask & VISIBLE) != 0) {
1070 HttpContext ctx = Context;
1071 TraceContext trace = (ctx != null) ? ctx.Trace : null;
1073 if ((trace != null) && trace.IsEnabled)
1074 pos = ctx.Response.GetOutputByteCount ();
1077 if ((trace != null) && trace.IsEnabled) {
1078 int size = ctx.Response.GetOutputByteCount () - pos;
1079 trace.SaveSize (this, size >= 0 ? size : 0);
1085 protected void RenderControl (HtmlTextWriter writer,
1086 ControlAdapter adapter)
1088 if ((stateMask & VISIBLE) != 0) {
1089 adapter.BeginRender (writer);
1090 adapter.Render (writer);
1091 adapter.EndRender (writer);
1096 public string ResolveUrl (string relativeUrl)
1098 if (relativeUrl == null)
1099 throw new ArgumentNullException ("relativeUrl");
1101 if (relativeUrl == "")
1104 if (relativeUrl [0] == '#')
1107 string ts = TemplateSourceDirectory;
1108 if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
1111 HttpResponse resp = Context.Response;
1112 return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
1115 internal bool HasRenderMethodDelegate () {
1116 return _renderMethodDelegate != null;
1119 [EditorBrowsable (EditorBrowsableState.Advanced)]
1120 public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
1122 _renderMethodDelegate = renderMethod;
1125 internal void LoadRecursive()
1128 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1129 string type_name = null;
1130 if (trace != null) {
1131 type_name = GetType ().Name;
1132 trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
1136 if (Adapter != null)
1137 Adapter.OnLoad (EventArgs.Empty);
1140 OnLoad (EventArgs.Empty);
1141 if (HasControls ()) {
1142 int len = Controls.Count;
1143 for (int i=0;i<len;i++)
1145 Control c = Controls[i];
1152 trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
1154 stateMask |= LOADED;
1157 internal void UnloadRecursive(Boolean dispose)
1160 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1161 string type_name = null;
1162 if (trace != null) {
1163 type_name = GetType ().Name;
1164 trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
1167 if (HasControls ()) {
1168 int len = Controls.Count;
1169 for (int i=0;i<len;i++)
1171 Control c = Controls[i];
1172 c.UnloadRecursive (dispose);
1178 trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
1181 if (Adapter != null)
1182 Adapter.OnUnload (EventArgs.Empty);
1185 OnUnload (EventArgs.Empty);
1190 internal void PreRenderRecursiveInternal()
1192 if ((stateMask & VISIBLE) != 0) {
1193 EnsureChildControls ();
1195 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1196 string type_name = null;
1197 if (trace != null) {
1198 type_name = GetType ().Name;
1199 trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
1203 if (Adapter != null)
1204 Adapter.OnPreRender (EventArgs.Empty);
1207 OnPreRender (EventArgs.Empty);
1208 if (!HasControls ())
1211 int len = Controls.Count;
1212 for (int i=0;i<len;i++)
1214 Control c = Controls[i];
1215 c.PreRenderRecursiveInternal ();
1219 trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
1222 stateMask |= PRERENDERED;
1225 internal void InitRecursive(Control namingContainer)
1228 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1229 string type_name = null;
1230 if (trace != null) {
1231 type_name = GetType ().Name;
1232 trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
1236 if (HasControls ()) {
1237 if ((stateMask & IS_NAMING_CONTAINER) != 0)
1238 namingContainer = this;
1240 if (namingContainer != null &&
1241 namingContainer._userId == null &&
1242 namingContainer.AutoID)
1243 namingContainer._userId = namingContainer.GetDefaultName () + "b";
1245 int len = Controls.Count;
1246 for (int i=0;i<len;i++)
1248 Control c = Controls[i];
1250 c._namingContainer = namingContainer;
1251 if (namingContainer != null && c._userId == null && c.AutoID)
1252 c._userId = namingContainer.GetDefaultName () + "c";
1253 c.InitRecursive (namingContainer);
1257 stateMask |= INITING;
1259 if (Adapter != null)
1260 Adapter.OnInit (EventArgs.Empty);
1263 OnInit (EventArgs.Empty);
1266 trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
1269 stateMask |= INITED;
1270 stateMask &= ~INITING;
1273 internal object SaveViewStateRecursive ()
1275 if (!EnableViewState)
1279 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1280 string type_name = null;
1281 if (trace != null) {
1282 type_name = GetType ().Name;
1283 trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
1287 ArrayList controlList = null;
1288 ArrayList controlStates = null;
1293 int len = Controls.Count;
1294 for (int i=0;i<len;i++)
1296 Control ctrl = Controls[i];
1297 object ctrlState = ctrl.SaveViewStateRecursive ();
1299 if (ctrlState == null)
1302 if (controlList == null)
1304 controlList = new ArrayList ();
1305 controlStates = new ArrayList ();
1308 controlList.Add (idx);
1309 controlStates.Add (ctrlState);
1313 object thisState = SaveViewState ();
1314 if (thisState == null && controlList == null && controlStates == null) {
1316 if (trace != null) {
1317 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
1318 trace.SaveViewState (this, null);
1325 if (trace != null) {
1326 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
1327 trace.SaveViewState (this, thisState);
1330 return new Triplet (thisState, controlList, controlStates);
1333 internal void LoadViewStateRecursive (object savedState)
1335 if (!EnableViewState || savedState == null)
1339 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1340 string type_name = null;
1341 if (trace != null) {
1342 type_name = GetType ().Name;
1343 trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
1346 Triplet savedInfo = (Triplet) savedState;
1347 LoadViewState (savedInfo.First);
1349 ArrayList controlList = savedInfo.Second as ArrayList;
1350 if (controlList == null)
1352 ArrayList controlStates = savedInfo.Third as ArrayList;
1353 int nControls = controlList.Count;
1354 for (int i = 0; i < nControls; i++) {
1355 int k = (int) controlList [i];
1356 if (k < Controls.Count && controlStates != null) {
1357 Control c = Controls [k];
1358 c.LoadViewStateRecursive (controlStates [i]);
1360 if (pendingVS == null)
1361 pendingVS = new Hashtable ();
1363 pendingVS [k] = controlStates [i];
1369 trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
1371 stateMask |= VIEWSTATE_LOADED;
1374 internal bool AutoID
1376 get { return (stateMask & AUTOID) != 0; }
1378 if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
1381 SetMask (AUTOID, value);
1385 protected internal virtual void RemovedControl (Control control)
1387 control.UnloadRecursive (false);
1388 control._parent = null;
1389 control._page = null;
1390 control._namingContainer = null;
1396 string skinId = string.Empty;
1400 [DefaultValue (true)]
1401 public virtual bool EnableTheming
1403 get { return (stateMask & ENABLE_THEMING) != 0; }
1404 set { SetMask (ENABLE_THEMING, value); }
1409 [Filterable (false)]
1410 public virtual string SkinID
1412 get { return skinId; }
1413 set { skinId = value; }
1416 public string ResolveClientUrl (string url)
1418 throw new NotImplementedException ();
1421 ControlBuilder IControlBuilderAccessor.ControlBuilder {
1422 get {throw new NotImplementedException (); }
1425 IDictionary IControlDesignerAccessor.GetDesignModeState ()
1427 throw new NotImplementedException ();
1430 void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
1432 SetDesignModeState (designData);
1435 void IControlDesignerAccessor.SetOwnerControl (Control control)
1437 throw new NotImplementedException ();
1440 IDictionary IControlDesignerAccessor.UserData {
1441 get { throw new NotImplementedException (); }
1444 ExpressionBindingCollection expressionBindings;
1446 ExpressionBindingCollection IExpressionsAccessor.Expressions {
1448 if (expressionBindings == null)
1449 expressionBindings = new ExpressionBindingCollection ();
1450 return expressionBindings;
1454 bool IExpressionsAccessor.HasExpressions {
1456 return (expressionBindings != null && expressionBindings.Count > 0);
1461 public virtual void Focus()
1463 throw new NotImplementedException();
1466 protected internal virtual void LoadControlState (object state)
1470 protected internal virtual object SaveControlState ()
1475 protected virtual void DataBind (bool raiseOnDataBinding)
1477 bool foundDataItem = false;
1479 if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
1480 object o = DataBinder.GetDataItem (this, out foundDataItem);
1482 Page.PushDataItemContext (o);
1487 if (raiseOnDataBinding)
1488 OnDataBinding (EventArgs.Empty);
1493 Page.PopDataItemContext ();
1497 protected virtual IDictionary GetDesignModeState ()
1499 throw new NotImplementedException ();
1502 protected virtual void SetDesignModeState (IDictionary data)
1504 throw new NotImplementedException ();
1507 void IParserAccessor.AddParsedSubObject (object obj) {
1508 this.AddParsedSubObject (obj);
1511 DataBindingCollection IDataBindingsAccessor.DataBindings {
1513 if (dataBindings == null) {
1514 dataBindings = new DataBindingCollection ();
1516 return dataBindings;
1520 bool IDataBindingsAccessor.HasDataBindings {
1522 if (dataBindings != null && dataBindings.Count > 0) {