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) {
441 if (_controls != null)
445 SetMask (CHILD_CONTROLS_CREATED, value);
450 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
451 protected virtual HttpContext Context //DIT
456 if (_context != null)
459 return HttpContext.Current;
460 context = _parent.Context;
463 return HttpContext.Current;
467 protected EventHandlerList Events {
470 _events = new EventHandlerList ();
475 protected bool HasChildViewState {
477 return (pendingVS != null && pendingVS.Count > 0);
481 protected bool IsTrackingViewState {
482 get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
486 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
487 [WebSysDescription ("ViewState")]
488 protected virtual StateBag ViewState
492 if(_viewState == null)
493 _viewState = new StateBag (ViewStateIgnoresCase);
495 if (IsTrackingViewState)
496 _viewState.TrackViewState ();
503 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
504 protected virtual bool ViewStateIgnoresCase
511 internal bool AutoEventWireup {
512 get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
513 set { SetMask (AUTO_EVENT_WIREUP, value); }
516 internal void SetBindingContainer (bool isBC)
518 SetMask (BINDING_CONTAINER, isBC);
521 internal void ResetChildNames ()
526 string GetDefaultName ()
529 if (defaultNumberID > 99) {
530 defaultName = "_ctl" + defaultNumberID++;
532 defaultName = defaultNameArray [defaultNumberID++];
537 void NullifyUniqueID ()
543 foreach (Control c in _controls)
544 c.NullifyUniqueID ();
547 protected internal virtual void AddedControl (Control control, int index)
549 /* Ensure the control don't have more than 1 parent */
550 if (control._parent != null)
551 control._parent.Controls.Remove (control);
553 control._parent = this;
554 control._page = _page;
555 Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
558 control._namingContainer = nc;
559 if (control.AutoID == true && control._userId == null)
560 control._userId = nc.GetDefaultName ();
563 if ((stateMask & (INITING | INITED)) != 0)
564 control.InitRecursive (nc);
566 if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
567 if (pendingVS != null) {
568 object vs = pendingVS [index];
570 pendingVS.Remove (index);
571 if (pendingVS.Count == 0)
574 control.LoadViewStateRecursive (vs);
579 if ((stateMask & LOADED) != 0)
580 control.LoadRecursive ();
582 if ((stateMask & PRERENDERED) != 0)
583 control.PreRenderRecursiveInternal ();
586 protected virtual void AddParsedSubObject(object obj) //DIT
588 Control c = obj as Control;
589 if (c != null) Controls.Add(c);
593 [EditorBrowsable (EditorBrowsableState.Advanced)]
594 public virtual void ApplyStyleSheetSkin (Page page)
596 throw new NotImplementedException ();
600 protected void BuildProfileTree(string parentId, bool calcViewState)
606 protected void ClearChildControlState ()
608 throw new NotImplementedException ();
611 protected void ClearChildState ()
613 throw new NotImplementedException ();
617 protected void ClearChildViewState ()
627 virtual void CreateChildControls() {} //DIT
629 protected virtual ControlCollection CreateControlCollection() //DIT
631 return new ControlCollection(this);
634 protected virtual void EnsureChildControls ()
636 if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
637 stateMask |= CREATING_CONTROLS;
640 Adapter.CreateChildControls ();
643 CreateChildControls();
644 ChildControlsCreated = true;
645 stateMask &= ~CREATING_CONTROLS;
650 protected void EnsureID ()
652 throw new NotImplementedException ();
655 protected bool HasEvents ()
657 throw new NotImplementedException ();
663 protected bool IsLiteralContent()
665 if (HasControls () && _controls.Count == 1 && (_controls [0] is LiteralControl))
671 [WebSysDescription ("")]
672 public virtual Control FindControl (string id)
674 return FindControl (id, 0);
677 Control LookForControlByName (string id)
682 Control result = null;
683 foreach (Control c in _controls) {
684 if (String.Compare (id, c._userId, true) == 0) {
685 if (result != null && result != c) {
686 throw new HttpException ("1 Found more than one control with ID '" + id + "'");
693 if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
694 Control child = c.LookForControlByName (id);
696 if (result != null && result != child)
697 throw new HttpException ("2 Found more than one control with ID '" + id + "'");
707 protected virtual Control FindControl (string id, int pathOffset)
709 EnsureChildControls ();
710 Control namingContainer = null;
711 if ((stateMask & IS_NAMING_CONTAINER) == 0) {
712 namingContainer = NamingContainer;
713 if (namingContainer == null)
716 return namingContainer.FindControl (id, pathOffset);
722 int colon = id.IndexOf (':', pathOffset);
724 return LookForControlByName (id.Substring (pathOffset));
726 string idfound = id.Substring (pathOffset, colon - pathOffset);
727 namingContainer = LookForControlByName (idfound);
728 if (namingContainer == null)
731 return namingContainer.FindControl (id, colon + 1);
734 protected virtual void LoadViewState(object savedState)
736 if (savedState != null) {
737 ViewState.LoadViewState (savedState);
738 object o = ViewState ["Visible"];
740 SetMask (VISIBLE, (bool) o);
741 stateMask |= VISIBLE_CHANGED;
746 [MonoTODO("Secure?")]
747 protected string MapPathSecure(string virtualPath)
749 string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
750 return Context.Request.MapPath (combined);
753 protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
756 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
757 string type_name = null;
759 type_name = GetType ().Name;
760 trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
766 protected virtual void OnDataBinding (EventArgs e)
768 if ((event_mask & databinding_mask) != 0) {
769 EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
772 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
773 string type_name = null;
775 type_name = GetType ().Name;
776 trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
789 virtual void OnInit (EventArgs e)
791 if ((event_mask & init_mask) != 0) {
792 EventHandler eh = (EventHandler)(_events [InitEvent]);
795 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
796 string type_name = null;
798 type_name = GetType ().Name;
799 trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
812 virtual void OnLoad (EventArgs e)
814 if ((event_mask & load_mask) != 0) {
815 EventHandler eh = (EventHandler)(_events [LoadEvent]);
818 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
819 string type_name = null;
821 type_name = GetType ().Name;
822 trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
835 virtual void OnPreRender (EventArgs e)
837 if ((event_mask & prerender_mask) != 0) {
838 EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
841 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
842 string type_name = null;
844 type_name = GetType ().Name;
845 trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
858 virtual void OnUnload(EventArgs e)
860 if ((event_mask & unload_mask) != 0) {
861 EventHandler eh = (EventHandler)(_events [UnloadEvent]);
864 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
865 string type_name = null;
867 type_name = GetType ().Name;
868 trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
877 protected internal Stream OpenFile (string path)
879 throw new NotImplementedException ();
883 protected void RaiseBubbleEvent(object source, EventArgs args)
888 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
889 string type_name = null;
891 type_name = GetType ().Name;
892 trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
895 if (c.OnBubbleEvent (source, args)) {
898 trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
904 trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
915 virtual void Render(HtmlTextWriter writer) //DIT
917 RenderChildren(writer);
925 virtual void RenderChildren (HtmlTextWriter writer) //DIT
927 if (_renderMethodDelegate != null) {
928 _renderMethodDelegate (writer, this);
929 } else if (_controls != null) {
930 int len = _controls.Count;
931 for (int i = 0; i < len; i++) {
932 Control c = _controls [i];
934 if (c.Adapter != null)
935 c.RenderControl (writer, c.Adapter);
938 c.RenderControl (writer);
944 protected virtual ControlAdapter ResolveAdapter ()
946 throw new NotImplementedException ();
950 protected virtual object SaveViewState ()
952 if ((stateMask & VISIBLE_CHANGED) != 0) {
953 ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
954 } else if (_viewState == null) {
958 return _viewState.SaveViewState ();
961 protected virtual void TrackViewState()
963 if (_viewState != null)
964 _viewState.TrackViewState ();
966 stateMask |= TRACK_VIEWSTATE;
969 public virtual void Dispose ()
971 if ((event_mask & disposed_mask) != 0) {
972 EventHandler eh = (EventHandler)(_events [DisposedEvent]);
973 if (eh != null) eh (this, EventArgs.Empty);
977 [WebCategory ("FIXME")]
978 [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
979 public event EventHandler DataBinding {
981 event_mask |= databinding_mask;
982 Events.AddHandler (DataBindingEvent, value);
984 remove { Events.RemoveHandler (DataBindingEvent, value); }
987 [WebSysDescription ("Raised when the contol is disposed.")]
988 public event EventHandler Disposed {
990 event_mask |= disposed_mask;
991 Events.AddHandler (DisposedEvent, value);
993 remove { Events.RemoveHandler (DisposedEvent, value); }
996 [WebSysDescription ("Raised when the page containing the control is initialized.")]
997 public event EventHandler Init {
999 event_mask |= init_mask;
1000 Events.AddHandler (InitEvent, value);
1002 remove { Events.RemoveHandler (InitEvent, value); }
1005 [WebSysDescription ("Raised after the page containing the control has been loaded.")]
1006 public event EventHandler Load {
1008 event_mask |= load_mask;
1009 Events.AddHandler (LoadEvent, value);
1011 remove { Events.RemoveHandler (LoadEvent, value); }
1014 [WebSysDescription ("Raised before the page containing the control is rendered.")]
1015 public event EventHandler PreRender {
1017 event_mask |= prerender_mask;
1018 Events.AddHandler (PreRenderEvent, value);
1020 remove { Events.RemoveHandler (PreRenderEvent, value); }
1023 [WebSysDescription ("Raised when the page containing the control is unloaded.")]
1024 public event EventHandler Unload {
1026 event_mask |= unload_mask;
1027 Events.AddHandler (UnloadEvent, value);
1029 remove { Events.RemoveHandler (UnloadEvent, value); }
1032 public virtual void DataBind() //DIT
1037 OnDataBinding (EventArgs.Empty);
1046 void DataBindChildren ()
1048 if (!HasControls ())
1051 int len = _controls.Count;
1052 for (int i = 0; i < len; i++) {
1053 Control c = _controls [i];
1059 public virtual bool HasControls ()
1061 return (_controls != null && _controls.Count > 0);
1069 void RenderControl (HtmlTextWriter writer)
1071 if ((stateMask & VISIBLE) != 0) {
1072 HttpContext ctx = Context;
1073 TraceContext trace = (ctx != null) ? ctx.Trace : null;
1075 if ((trace != null) && trace.IsEnabled)
1076 pos = ctx.Response.GetOutputByteCount ();
1079 if ((trace != null) && trace.IsEnabled) {
1080 int size = ctx.Response.GetOutputByteCount () - pos;
1081 trace.SaveSize (this, size >= 0 ? size : 0);
1087 protected void RenderControl (HtmlTextWriter writer,
1088 ControlAdapter adapter)
1090 if ((stateMask & VISIBLE) != 0) {
1091 adapter.BeginRender (writer);
1092 adapter.Render (writer);
1093 adapter.EndRender (writer);
1098 public string ResolveUrl (string relativeUrl)
1100 if (relativeUrl == null)
1101 throw new ArgumentNullException ("relativeUrl");
1103 if (relativeUrl == "")
1106 if (relativeUrl [0] == '#')
1109 string ts = TemplateSourceDirectory;
1110 if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
1113 HttpResponse resp = Context.Response;
1114 return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
1117 internal bool HasRenderMethodDelegate () {
1118 return _renderMethodDelegate != null;
1121 [EditorBrowsable (EditorBrowsableState.Advanced)]
1122 public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
1124 _renderMethodDelegate = renderMethod;
1127 internal void LoadRecursive()
1130 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1131 string type_name = null;
1132 if (trace != null) {
1133 type_name = GetType ().Name;
1134 trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
1138 if (Adapter != null)
1139 Adapter.OnLoad (EventArgs.Empty);
1142 OnLoad (EventArgs.Empty);
1143 if (HasControls ()) {
1144 int len = _controls.Count;
1145 for (int i=0;i<len;i++)
1147 Control c = _controls[i];
1154 trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
1156 stateMask |= LOADED;
1159 internal void UnloadRecursive(Boolean dispose)
1162 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1163 string type_name = null;
1164 if (trace != null) {
1165 type_name = GetType ().Name;
1166 trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
1169 if (HasControls ()) {
1170 int len = _controls.Count;
1171 for (int i=0;i<len;i++)
1173 Control c = _controls[i];
1174 c.UnloadRecursive (dispose);
1180 trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
1183 if (Adapter != null)
1184 Adapter.OnUnload (EventArgs.Empty);
1187 OnUnload (EventArgs.Empty);
1192 internal void PreRenderRecursiveInternal()
1194 if ((stateMask & VISIBLE) != 0) {
1195 EnsureChildControls ();
1197 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1198 string type_name = null;
1199 if (trace != null) {
1200 type_name = GetType ().Name;
1201 trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
1205 if (Adapter != null)
1206 Adapter.OnPreRender (EventArgs.Empty);
1209 OnPreRender (EventArgs.Empty);
1210 if (!HasControls ())
1213 int len = _controls.Count;
1214 for (int i=0;i<len;i++)
1216 Control c = _controls[i];
1217 c.PreRenderRecursiveInternal ();
1221 trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
1224 stateMask |= PRERENDERED;
1227 internal void InitRecursive(Control namingContainer)
1230 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1231 string type_name = null;
1232 if (trace != null) {
1233 type_name = GetType ().Name;
1234 trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
1238 if (HasControls ()) {
1239 if ((stateMask & IS_NAMING_CONTAINER) != 0)
1240 namingContainer = this;
1242 if (namingContainer != null &&
1243 namingContainer._userId == null &&
1244 namingContainer.AutoID)
1245 namingContainer._userId = namingContainer.GetDefaultName () + "b";
1247 int len = _controls.Count;
1248 for (int i=0;i<len;i++)
1250 Control c = _controls[i];
1252 c._namingContainer = namingContainer;
1253 if (namingContainer != null && c._userId == null && c.AutoID)
1254 c._userId = namingContainer.GetDefaultName () + "c";
1255 c.InitRecursive (namingContainer);
1259 stateMask |= INITING;
1261 if (Adapter != null)
1262 Adapter.OnInit (EventArgs.Empty);
1265 OnInit (EventArgs.Empty);
1268 trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
1271 stateMask |= INITED;
1272 stateMask &= ~INITING;
1275 internal object SaveViewStateRecursive ()
1277 if (!EnableViewState)
1281 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1282 string type_name = null;
1283 if (trace != null) {
1284 type_name = GetType ().Name;
1285 trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
1289 ArrayList controlList = null;
1290 ArrayList controlStates = null;
1295 int len = _controls.Count;
1296 for (int i=0;i<len;i++)
1298 Control ctrl = _controls[i];
1299 object ctrlState = ctrl.SaveViewStateRecursive ();
1301 if (ctrlState == null)
1304 if (controlList == null)
1306 controlList = new ArrayList ();
1307 controlStates = new ArrayList ();
1310 controlList.Add (idx);
1311 controlStates.Add (ctrlState);
1315 object thisState = SaveViewState ();
1316 if (thisState == null && controlList == null && controlStates == null) {
1318 if (trace != null) {
1319 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
1320 trace.SaveViewState (this, null);
1327 if (trace != null) {
1328 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
1329 trace.SaveViewState (this, thisState);
1332 return new Triplet (thisState, controlList, controlStates);
1335 internal void LoadViewStateRecursive (object savedState)
1337 if (!EnableViewState || savedState == null)
1341 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1342 string type_name = null;
1343 if (trace != null) {
1344 type_name = GetType ().Name;
1345 trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
1348 Triplet savedInfo = (Triplet) savedState;
1349 LoadViewState (savedInfo.First);
1351 ArrayList controlList = savedInfo.Second as ArrayList;
1352 if (controlList == null)
1354 ArrayList controlStates = savedInfo.Third as ArrayList;
1355 int nControls = controlList.Count;
1356 for (int i = 0; i < nControls; i++) {
1357 int k = (int) controlList [i];
1358 if (k < Controls.Count && controlStates != null) {
1359 Control c = Controls [k];
1360 c.LoadViewStateRecursive (controlStates [i]);
1362 if (pendingVS == null)
1363 pendingVS = new Hashtable ();
1365 pendingVS [k] = controlStates [i];
1371 trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
1373 stateMask |= VIEWSTATE_LOADED;
1376 internal bool AutoID
1378 get { return (stateMask & AUTOID) != 0; }
1380 if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
1383 SetMask (AUTOID, value);
1387 protected internal virtual void RemovedControl (Control control)
1389 control.UnloadRecursive (false);
1390 control._parent = null;
1391 control._page = null;
1392 control._namingContainer = null;
1398 string skinId = string.Empty;
1402 [DefaultValue (true)]
1403 public virtual bool EnableTheming
1405 get { return (stateMask & ENABLE_THEMING) != 0; }
1406 set { SetMask (ENABLE_THEMING, value); }
1411 [Filterable (false)]
1412 public virtual string SkinID
1414 get { return skinId; }
1415 set { skinId = value; }
1418 public string ResolveClientUrl (string url)
1420 throw new NotImplementedException ();
1423 ControlBuilder IControlBuilderAccessor.ControlBuilder {
1424 get {throw new NotImplementedException (); }
1427 IDictionary IControlDesignerAccessor.GetDesignModeState ()
1429 throw new NotImplementedException ();
1432 void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
1434 SetDesignModeState (designData);
1437 void IControlDesignerAccessor.SetOwnerControl (Control control)
1439 throw new NotImplementedException ();
1442 IDictionary IControlDesignerAccessor.UserData {
1443 get { throw new NotImplementedException (); }
1446 ExpressionBindingCollection expressionBindings;
1448 ExpressionBindingCollection IExpressionsAccessor.Expressions {
1450 if (expressionBindings == null)
1451 expressionBindings = new ExpressionBindingCollection ();
1452 return expressionBindings;
1456 bool IExpressionsAccessor.HasExpressions {
1458 return (expressionBindings != null && expressionBindings.Count > 0);
1463 public virtual void Focus()
1465 throw new NotImplementedException();
1468 protected internal virtual void LoadControlState (object state)
1472 protected internal virtual object SaveControlState ()
1477 protected virtual void DataBind (bool raiseOnDataBinding)
1479 bool foundDataItem = false;
1481 if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
1482 object o = DataBinder.GetDataItem (this, out foundDataItem);
1484 Page.PushDataItemContext (o);
1489 if (raiseOnDataBinding)
1490 OnDataBinding (EventArgs.Empty);
1495 Page.PopDataItemContext ();
1499 protected virtual IDictionary GetDesignModeState ()
1501 throw new NotImplementedException ();
1504 protected virtual void SetDesignModeState (IDictionary data)
1506 throw new NotImplementedException ();
1509 void IParserAccessor.AddParsedSubObject (object obj) {
1510 this.AddParsedSubObject (obj);
1513 DataBindingCollection IDataBindingsAccessor.DataBindings {
1515 if (dataBindings == null) {
1516 dataBindings = new DataBindingCollection ();
1518 return dataBindings;
1522 bool IDataBindingsAccessor.HasDataBindings {
1524 if (dataBindings != null && dataBindings.Count > 0) {