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;
145 stateMask |= ENABLE_THEMING;
151 protected ControlAdapter Adapter
154 // for the time being, fool the
155 // Control machinery into thinking we
156 // don't have an Adapter. This will
157 // allow us to write all the rest of
158 // the Adapter handling code without
159 // having to worry about *having*
165 [EditorBrowsable (EditorBrowsableState.Advanced)]
167 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
168 public string AppRelativeTemplateSourceDirectory
171 throw new NotImplementedException ();
173 [EditorBrowsable (EditorBrowsableState.Never)]
175 throw new NotImplementedException ();
181 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
182 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
183 public Control BindingContainer {
185 Control container = NamingContainer;
186 if ((container.stateMask & BINDING_CONTAINER) == 0)
187 container = container.BindingContainer;
192 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
194 [WebSysDescription ("An Identification of the control that is rendered.")]
195 public virtual string ClientID {
197 string client = UniqueID;
200 client = client.Replace (':', '_');
207 protected char ClientIDSeparator
210 throw new NotImplementedException ();
215 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
217 [WebSysDescription ("The child controls of this control.")]
218 public virtual ControlCollection Controls //DIT
222 if (_controls == null) _controls = CreateControlCollection();
228 protected internal bool DesignMode
231 throw new NotImplementedException ();
236 [DefaultValue (true), WebCategory ("Behavior")]
237 [WebSysDescription ("An Identification of the control that is rendered.")]
241 public virtual bool EnableViewState {
242 get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
243 set { SetMask (ENABLE_VIEWSTATE, value); }
246 [MergableProperty (false), ParenthesizePropertyName (true)]
247 [WebSysDescription ("The name of the control that is rendered.")]
249 [Filterable (false), Themeable (false)]
252 public virtual string ID {
254 return (((stateMask & ID_SET) != 0) ? _userId : null);
268 protected char IdSeparator
271 throw new NotImplementedException ();
275 protected internal bool IsChildControlStateCleared
278 throw new NotImplementedException ();
282 protected internal bool IsViewStateEnabled
285 throw new NotImplementedException ();
289 protected bool LoadViewStateByID
292 throw new NotImplementedException ();
297 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
299 [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
300 public virtual Control NamingContainer {
302 if (_namingContainer == null && _parent != null) {
303 if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
304 _namingContainer = _parent.NamingContainer;
306 _namingContainer = _parent;
309 return _namingContainer;
313 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
315 [WebSysDescription ("The webpage that this control resides on.")]
319 public virtual Page Page //DIT
323 if (_page == null && _parent != null) _page = _parent.Page;
332 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
334 [WebSysDescription ("The parent control of this control.")]
335 public virtual Control Parent //DIT
343 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
344 [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
345 [WebSysDescription ("The site this control is part of.")]
346 public ISite Site //DIT
360 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
361 public TemplateControl TemplateControl
364 return _templateControl;
366 [EditorBrowsable (EditorBrowsableState.Never)]
368 _templateControl = value;
373 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
375 [WebSysDescription ("A virtual directory containing the parent of the control.")]
376 public virtual string TemplateSourceDirectory {
377 get { return (_parent == null) ? String.Empty : _parent.TemplateSourceDirectory; }
380 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
382 [WebSysDescription ("The unique ID of the control.")]
383 public virtual string UniqueID {
385 if (uniqueID != null)
388 if (_namingContainer == null) {
389 if ((stateMask & IS_NAMING_CONTAINER) == 0)
390 _namingContainer = NamingContainer;
391 if (_namingContainer == null)
396 _userId = _namingContainer.GetDefaultName ();
398 string prefix = _namingContainer.UniqueID;
399 if (_namingContainer == _page || prefix == null) {
404 uniqueID = prefix + ":" + _userId;
409 void SetMask (int m, bool val)
417 [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
418 [WebSysDescription ("Visiblity state of the control.")]
419 public virtual bool Visible {
421 if ((stateMask & VISIBLE) == 0)
425 return _parent.Visible;
431 if ((value && (stateMask & VISIBLE) == 0) ||
432 (!value && (stateMask & VISIBLE) != 0)) {
433 if (IsTrackingViewState)
434 stateMask |= VISIBLE_CHANGED;
437 SetMask (VISIBLE, value);
441 protected bool ChildControlsCreated {
442 get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
444 if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0) {
445 if (_controls != null)
449 SetMask (CHILD_CONTROLS_CREATED, value);
454 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
455 protected virtual HttpContext Context //DIT
460 if (_context != null)
463 return HttpContext.Current;
464 context = _parent.Context;
467 return HttpContext.Current;
471 protected EventHandlerList Events {
474 _events = new EventHandlerList ();
479 protected bool HasChildViewState {
481 return (pendingVS != null && pendingVS.Count > 0);
485 protected bool IsTrackingViewState {
486 get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
490 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
491 [WebSysDescription ("ViewState")]
492 protected virtual StateBag ViewState
496 if(_viewState == null)
497 _viewState = new StateBag (ViewStateIgnoresCase);
499 if (IsTrackingViewState)
500 _viewState.TrackViewState ();
507 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
508 protected virtual bool ViewStateIgnoresCase
515 internal bool AutoEventWireup {
516 get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
517 set { SetMask (AUTO_EVENT_WIREUP, value); }
520 internal void SetBindingContainer (bool isBC)
522 SetMask (BINDING_CONTAINER, isBC);
525 internal void ResetChildNames ()
530 string GetDefaultName ()
533 if (defaultNumberID > 99) {
534 defaultName = "_ctl" + defaultNumberID++;
536 defaultName = defaultNameArray [defaultNumberID++];
541 void NullifyUniqueID ()
547 foreach (Control c in _controls)
548 c.NullifyUniqueID ();
551 protected internal virtual void AddedControl (Control control, int index)
553 /* Ensure the control don't have more than 1 parent */
554 if (control._parent != null)
555 control._parent.Controls.Remove (control);
557 control._parent = this;
558 control._page = _page;
559 Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
562 control._namingContainer = nc;
563 if (control.AutoID == true && control._userId == null)
564 control._userId = nc.GetDefaultName ();
567 if ((stateMask & (INITING | INITED)) != 0)
568 control.InitRecursive (nc);
570 if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
571 if (pendingVS != null) {
572 object vs = pendingVS [index];
574 pendingVS.Remove (index);
575 if (pendingVS.Count == 0)
578 control.LoadViewStateRecursive (vs);
583 if ((stateMask & LOADED) != 0)
584 control.LoadRecursive ();
586 if ((stateMask & PRERENDERED) != 0)
587 control.PreRenderRecursiveInternal ();
590 protected virtual void AddParsedSubObject(object obj) //DIT
592 Control c = obj as Control;
593 if (c != null) Controls.Add(c);
598 [EditorBrowsable (EditorBrowsableState.Advanced)]
599 public virtual void ApplyStyleSheetSkin (Page page)
601 if (!EnableTheming) /* this enough? */
604 /* apply the style sheet skin here */
605 if (page.StyleSheetTheme != null) {
606 ControlSkin cs = page.StyleSheetPageTheme.GetControlSkin (GetType(), SkinID);
613 protected void BuildProfileTree(string parentId, bool calcViewState)
619 protected void ClearChildControlState ()
621 throw new NotImplementedException ();
624 protected void ClearChildState ()
626 throw new NotImplementedException ();
630 protected void ClearChildViewState ()
640 virtual void CreateChildControls() {} //DIT
642 protected virtual ControlCollection CreateControlCollection() //DIT
644 return new ControlCollection(this);
647 protected virtual void EnsureChildControls ()
649 if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
650 stateMask |= CREATING_CONTROLS;
653 Adapter.CreateChildControls ();
656 CreateChildControls();
657 ChildControlsCreated = true;
658 stateMask &= ~CREATING_CONTROLS;
663 protected void EnsureID ()
665 throw new NotImplementedException ();
668 protected bool HasEvents ()
670 throw new NotImplementedException ();
676 protected bool IsLiteralContent()
678 if (HasControls () && _controls.Count == 1 && (_controls [0] is LiteralControl))
684 [WebSysDescription ("")]
685 public virtual Control FindControl (string id)
687 return FindControl (id, 0);
690 Control LookForControlByName (string id)
695 Control result = null;
696 foreach (Control c in _controls) {
697 if (String.Compare (id, c._userId, true) == 0) {
698 if (result != null && result != c) {
699 throw new HttpException ("1 Found more than one control with ID '" + id + "'");
706 if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ()) {
707 Control child = c.LookForControlByName (id);
709 if (result != null && result != child)
710 throw new HttpException ("2 Found more than one control with ID '" + id + "'");
720 protected virtual Control FindControl (string id, int pathOffset)
722 EnsureChildControls ();
723 Control namingContainer = null;
724 if ((stateMask & IS_NAMING_CONTAINER) == 0) {
725 namingContainer = NamingContainer;
726 if (namingContainer == null)
729 return namingContainer.FindControl (id, pathOffset);
735 int colon = id.IndexOf (':', pathOffset);
737 return LookForControlByName (id.Substring (pathOffset));
739 string idfound = id.Substring (pathOffset, colon - pathOffset);
740 namingContainer = LookForControlByName (idfound);
741 if (namingContainer == null)
744 return namingContainer.FindControl (id, colon + 1);
747 protected virtual void LoadViewState(object savedState)
749 if (savedState != null) {
750 ViewState.LoadViewState (savedState);
751 object o = ViewState ["Visible"];
753 SetMask (VISIBLE, (bool) o);
754 stateMask |= VISIBLE_CHANGED;
759 [MonoTODO("Secure?")]
760 protected string MapPathSecure(string virtualPath)
762 string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
763 return Context.Request.MapPath (combined);
766 protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT
769 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
770 string type_name = null;
772 type_name = GetType ().Name;
773 trace.Write ("control", String.Format ("OnBubbleEvent {0} {1}", _userId, type_name));
779 protected virtual void OnDataBinding (EventArgs e)
781 if ((event_mask & databinding_mask) != 0) {
782 EventHandler eh = (EventHandler)(_events [DataBindingEvent]);
785 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
786 string type_name = null;
788 type_name = GetType ().Name;
789 trace.Write ("control", String.Format ("OnDataBinding {0} {1}", _userId, type_name));
802 virtual void OnInit (EventArgs e)
804 if ((event_mask & init_mask) != 0) {
805 EventHandler eh = (EventHandler)(_events [InitEvent]);
808 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
809 string type_name = null;
811 type_name = GetType ().Name;
812 trace.Write ("control", String.Format ("OnInit {0} {1}", _userId, type_name));
825 virtual void OnLoad (EventArgs e)
827 if ((event_mask & load_mask) != 0) {
828 EventHandler eh = (EventHandler)(_events [LoadEvent]);
831 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
832 string type_name = null;
834 type_name = GetType ().Name;
835 trace.Write ("control", String.Format ("OnLoad {0} {1}", _userId, type_name));
848 virtual void OnPreRender (EventArgs e)
850 if ((event_mask & prerender_mask) != 0) {
851 EventHandler eh = (EventHandler)(_events [PreRenderEvent]);
854 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
855 string type_name = null;
857 type_name = GetType ().Name;
858 trace.Write ("control", String.Format ("OnPreRender {0} {1}", _userId, type_name));
871 virtual void OnUnload(EventArgs e)
873 if ((event_mask & unload_mask) != 0) {
874 EventHandler eh = (EventHandler)(_events [UnloadEvent]);
877 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
878 string type_name = null;
880 type_name = GetType ().Name;
881 trace.Write ("control", String.Format ("OnUnload {0} {1}", _userId, type_name));
890 protected internal Stream OpenFile (string path)
892 throw new NotImplementedException ();
896 protected void RaiseBubbleEvent(object source, EventArgs args)
901 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
902 string type_name = null;
904 type_name = GetType ().Name;
905 trace.Write ("control", String.Format ("RaiseBubbleEvent {0} {1}", _userId, type_name));
908 if (c.OnBubbleEvent (source, args)) {
911 trace.Write ("control", String.Format ("End RaiseBubbleEvent (false) {0} {1}", _userId, type_name));
917 trace.Write ("control", String.Format ("End RaiseBubbleEvent (true) {0} {1}", _userId, type_name));
928 virtual void Render(HtmlTextWriter writer) //DIT
930 RenderChildren(writer);
938 virtual void RenderChildren (HtmlTextWriter writer) //DIT
940 if (_renderMethodDelegate != null) {
941 _renderMethodDelegate (writer, this);
942 } else if (_controls != null) {
943 int len = _controls.Count;
944 for (int i = 0; i < len; i++) {
945 Control c = _controls [i];
947 if (c.Adapter != null)
948 c.RenderControl (writer, c.Adapter);
951 c.RenderControl (writer);
957 protected virtual ControlAdapter ResolveAdapter ()
959 throw new NotImplementedException ();
963 protected virtual object SaveViewState ()
965 if ((stateMask & VISIBLE_CHANGED) != 0) {
966 ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
967 } else if (_viewState == null) {
971 return _viewState.SaveViewState ();
974 protected virtual void TrackViewState()
976 if (_viewState != null)
977 _viewState.TrackViewState ();
979 stateMask |= TRACK_VIEWSTATE;
982 public virtual void Dispose ()
984 if ((event_mask & disposed_mask) != 0) {
985 EventHandler eh = (EventHandler)(_events [DisposedEvent]);
986 if (eh != null) eh (this, EventArgs.Empty);
990 [WebCategory ("FIXME")]
991 [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
992 public event EventHandler DataBinding {
994 event_mask |= databinding_mask;
995 Events.AddHandler (DataBindingEvent, value);
997 remove { Events.RemoveHandler (DataBindingEvent, value); }
1000 [WebSysDescription ("Raised when the contol is disposed.")]
1001 public event EventHandler Disposed {
1003 event_mask |= disposed_mask;
1004 Events.AddHandler (DisposedEvent, value);
1006 remove { Events.RemoveHandler (DisposedEvent, value); }
1009 [WebSysDescription ("Raised when the page containing the control is initialized.")]
1010 public event EventHandler Init {
1012 event_mask |= init_mask;
1013 Events.AddHandler (InitEvent, value);
1015 remove { Events.RemoveHandler (InitEvent, value); }
1018 [WebSysDescription ("Raised after the page containing the control has been loaded.")]
1019 public event EventHandler Load {
1021 event_mask |= load_mask;
1022 Events.AddHandler (LoadEvent, value);
1024 remove { Events.RemoveHandler (LoadEvent, value); }
1027 [WebSysDescription ("Raised before the page containing the control is rendered.")]
1028 public event EventHandler PreRender {
1030 event_mask |= prerender_mask;
1031 Events.AddHandler (PreRenderEvent, value);
1033 remove { Events.RemoveHandler (PreRenderEvent, value); }
1036 [WebSysDescription ("Raised when the page containing the control is unloaded.")]
1037 public event EventHandler Unload {
1039 event_mask |= unload_mask;
1040 Events.AddHandler (UnloadEvent, value);
1042 remove { Events.RemoveHandler (UnloadEvent, value); }
1045 public virtual void DataBind() //DIT
1050 OnDataBinding (EventArgs.Empty);
1059 void DataBindChildren ()
1061 if (!HasControls ())
1064 int len = _controls.Count;
1065 for (int i = 0; i < len; i++) {
1066 Control c = _controls [i];
1072 public virtual bool HasControls ()
1074 return (_controls != null && _controls.Count > 0);
1082 void RenderControl (HtmlTextWriter writer)
1084 if ((stateMask & VISIBLE) != 0) {
1085 HttpContext ctx = Context;
1086 TraceContext trace = (ctx != null) ? ctx.Trace : null;
1088 if ((trace != null) && trace.IsEnabled)
1089 pos = ctx.Response.GetOutputByteCount ();
1092 if ((trace != null) && trace.IsEnabled) {
1093 int size = ctx.Response.GetOutputByteCount () - pos;
1094 trace.SaveSize (this, size >= 0 ? size : 0);
1100 protected void RenderControl (HtmlTextWriter writer,
1101 ControlAdapter adapter)
1103 if ((stateMask & VISIBLE) != 0) {
1104 adapter.BeginRender (writer);
1105 adapter.Render (writer);
1106 adapter.EndRender (writer);
1111 public string ResolveUrl (string relativeUrl)
1113 if (relativeUrl == null)
1114 throw new ArgumentNullException ("relativeUrl");
1116 if (relativeUrl == "")
1119 if (relativeUrl [0] == '#')
1122 string ts = TemplateSourceDirectory;
1123 if (ts == "" || !UrlUtils.IsRelativeUrl (relativeUrl))
1126 HttpResponse resp = Context.Response;
1127 return resp.ApplyAppPathModifier (UrlUtils.Combine (ts, relativeUrl));
1130 internal bool HasRenderMethodDelegate () {
1131 return _renderMethodDelegate != null;
1134 [EditorBrowsable (EditorBrowsableState.Advanced)]
1135 public void SetRenderMethodDelegate(RenderMethod renderMethod) //DIT
1137 _renderMethodDelegate = renderMethod;
1140 internal void LoadRecursive()
1143 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1144 string type_name = null;
1145 if (trace != null) {
1146 type_name = GetType ().Name;
1147 trace.Write ("control", String.Format ("LoadRecursive {0} {1}", _userId, type_name));
1151 if (Adapter != null)
1152 Adapter.OnLoad (EventArgs.Empty);
1155 OnLoad (EventArgs.Empty);
1156 if (HasControls ()) {
1157 int len = _controls.Count;
1158 for (int i=0;i<len;i++)
1160 Control c = _controls[i];
1167 trace.Write ("control", String.Format ("End LoadRecursive {0} {1}", _userId, type_name));
1169 stateMask |= LOADED;
1172 internal void UnloadRecursive(Boolean dispose)
1175 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1176 string type_name = null;
1177 if (trace != null) {
1178 type_name = GetType ().Name;
1179 trace.Write ("control", String.Format ("UnloadRecursive {0} {1}", _userId, type_name));
1182 if (HasControls ()) {
1183 int len = _controls.Count;
1184 for (int i=0;i<len;i++)
1186 Control c = _controls[i];
1187 c.UnloadRecursive (dispose);
1193 trace.Write ("control", String.Format ("End UnloadRecursive {0} {1}", _userId, type_name));
1196 if (Adapter != null)
1197 Adapter.OnUnload (EventArgs.Empty);
1200 OnUnload (EventArgs.Empty);
1205 internal void PreRenderRecursiveInternal()
1207 if ((stateMask & VISIBLE) != 0) {
1208 EnsureChildControls ();
1210 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1211 string type_name = null;
1212 if (trace != null) {
1213 type_name = GetType ().Name;
1214 trace.Write ("control", String.Format ("PreRenderRecursive {0} {1}", _userId, type_name));
1218 if (Adapter != null)
1219 Adapter.OnPreRender (EventArgs.Empty);
1222 OnPreRender (EventArgs.Empty);
1223 if (!HasControls ())
1226 int len = _controls.Count;
1227 for (int i=0;i<len;i++)
1229 Control c = _controls[i];
1230 c.PreRenderRecursiveInternal ();
1234 trace.Write ("control", String.Format ("End PreRenderRecursive {0} {1}", _userId, type_name));
1237 stateMask |= PRERENDERED;
1240 internal void InitRecursive(Control namingContainer)
1243 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1244 string type_name = null;
1245 if (trace != null) {
1246 type_name = GetType ().Name;
1247 trace.Write ("control", String.Format ("InitRecursive {0} {1}", _userId, type_name));
1251 if (HasControls ()) {
1252 if ((stateMask & IS_NAMING_CONTAINER) != 0)
1253 namingContainer = this;
1255 if (namingContainer != null &&
1256 namingContainer._userId == null &&
1257 namingContainer.AutoID)
1258 namingContainer._userId = namingContainer.GetDefaultName () + "b";
1260 int len = _controls.Count;
1261 for (int i=0;i<len;i++)
1263 Control c = _controls[i];
1265 c._namingContainer = namingContainer;
1266 if (namingContainer != null && c._userId == null && c.AutoID)
1267 c._userId = namingContainer.GetDefaultName () + "c";
1268 c.InitRecursive (namingContainer);
1272 stateMask |= INITING;
1274 if (Adapter != null)
1275 Adapter.OnInit (EventArgs.Empty);
1278 OnInit (EventArgs.Empty);
1281 trace.Write ("control", String.Format ("End InitRecursive {0} {1}", _userId, type_name));
1284 stateMask |= INITED;
1285 stateMask &= ~INITING;
1288 internal object SaveViewStateRecursive ()
1290 if (!EnableViewState)
1294 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1295 string type_name = null;
1296 if (trace != null) {
1297 type_name = GetType ().Name;
1298 trace.Write ("control", String.Format ("SaveViewStateRecursive {0} {1}", _userId, type_name));
1302 ArrayList controlList = null;
1303 ArrayList controlStates = null;
1308 int len = _controls.Count;
1309 for (int i=0;i<len;i++)
1311 Control ctrl = _controls[i];
1312 object ctrlState = ctrl.SaveViewStateRecursive ();
1314 if (ctrlState == null)
1317 if (controlList == null)
1319 controlList = new ArrayList ();
1320 controlStates = new ArrayList ();
1323 controlList.Add (idx);
1324 controlStates.Add (ctrlState);
1328 object thisState = SaveViewState ();
1329 if (thisState == null && controlList == null && controlStates == null) {
1331 if (trace != null) {
1332 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved nothing", _userId, type_name));
1333 trace.SaveViewState (this, null);
1340 if (trace != null) {
1341 trace.Write ("control", String.Format ("End SaveViewStateRecursive {0} {1} saved a Triplet", _userId, type_name));
1342 trace.SaveViewState (this, thisState);
1345 return new Triplet (thisState, controlList, controlStates);
1348 internal void LoadViewStateRecursive (object savedState)
1350 if (!EnableViewState || savedState == null)
1354 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1355 string type_name = null;
1356 if (trace != null) {
1357 type_name = GetType ().Name;
1358 trace.Write ("control", String.Format ("LoadViewStateRecursive {0} {1}", _userId, type_name));
1361 Triplet savedInfo = (Triplet) savedState;
1362 LoadViewState (savedInfo.First);
1364 ArrayList controlList = savedInfo.Second as ArrayList;
1365 if (controlList == null)
1367 ArrayList controlStates = savedInfo.Third as ArrayList;
1368 int nControls = controlList.Count;
1369 for (int i = 0; i < nControls; i++) {
1370 int k = (int) controlList [i];
1371 if (k < Controls.Count && controlStates != null) {
1372 Control c = Controls [k];
1373 c.LoadViewStateRecursive (controlStates [i]);
1375 if (pendingVS == null)
1376 pendingVS = new Hashtable ();
1378 pendingVS [k] = controlStates [i];
1384 trace.Write ("control", String.Format ("End LoadViewStateRecursive {0} {1}", _userId, type_name));
1386 stateMask |= VIEWSTATE_LOADED;
1390 internal ControlSkin controlSkin;
1392 internal void ApplyThemeRecursive ()
1395 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1396 string type_name = null;
1397 if (trace != null) {
1398 type_name = GetType ().Name;
1399 trace.Write ("control", String.Format ("ApplyThemeRecursive {0} {1}", _userId, type_name));
1402 ControlSkin controlSkin = Page.PageTheme.GetControlSkin (GetType(), SkinID);
1403 if (controlSkin != null)
1404 controlSkin.ApplySkin (this);
1406 if (HasControls ()) {
1407 int len = _controls.Count;
1408 for (int i=0;i<len;i++)
1410 Control c = _controls[i];
1411 c.ApplyThemeRecursive ();
1417 trace.Write ("control", String.Format ("End ApplyThemeRecursive {0} {1}", _userId, type_name));
1422 internal bool AutoID
1424 get { return (stateMask & AUTOID) != 0; }
1426 if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
1429 SetMask (AUTOID, value);
1433 protected internal virtual void RemovedControl (Control control)
1435 control.UnloadRecursive (false);
1436 control._parent = null;
1437 control._page = null;
1438 control._namingContainer = null;
1444 string skinId = string.Empty;
1448 [DefaultValue (true)]
1449 public virtual bool EnableTheming
1451 get { return (stateMask & ENABLE_THEMING) != 0; }
1452 set { SetMask (ENABLE_THEMING, value); }
1457 [Filterable (false)]
1458 public virtual string SkinID
1460 get { return skinId; }
1461 set { skinId = value; }
1464 public string ResolveClientUrl (string url)
1466 throw new NotImplementedException ();
1469 ControlBuilder IControlBuilderAccessor.ControlBuilder {
1470 get {throw new NotImplementedException (); }
1473 IDictionary IControlDesignerAccessor.GetDesignModeState ()
1475 throw new NotImplementedException ();
1478 void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
1480 SetDesignModeState (designData);
1483 void IControlDesignerAccessor.SetOwnerControl (Control control)
1485 throw new NotImplementedException ();
1488 IDictionary IControlDesignerAccessor.UserData {
1489 get { throw new NotImplementedException (); }
1492 ExpressionBindingCollection expressionBindings;
1494 ExpressionBindingCollection IExpressionsAccessor.Expressions {
1496 if (expressionBindings == null)
1497 expressionBindings = new ExpressionBindingCollection ();
1498 return expressionBindings;
1502 bool IExpressionsAccessor.HasExpressions {
1504 return (expressionBindings != null && expressionBindings.Count > 0);
1509 public virtual void Focus()
1511 throw new NotImplementedException();
1514 protected internal virtual void LoadControlState (object state)
1518 protected internal virtual object SaveControlState ()
1523 protected virtual void DataBind (bool raiseOnDataBinding)
1525 bool foundDataItem = false;
1527 if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
1528 object o = DataBinder.GetDataItem (this, out foundDataItem);
1530 Page.PushDataItemContext (o);
1535 if (raiseOnDataBinding)
1536 OnDataBinding (EventArgs.Empty);
1541 Page.PopDataItemContext ();
1545 protected virtual IDictionary GetDesignModeState ()
1547 throw new NotImplementedException ();
1550 protected virtual void SetDesignModeState (IDictionary data)
1552 throw new NotImplementedException ();
1555 void IParserAccessor.AddParsedSubObject (object obj) {
1556 this.AddParsedSubObject (obj);
1559 DataBindingCollection IDataBindingsAccessor.DataBindings {
1561 if (dataBindings == null) {
1562 dataBindings = new DataBindingCollection ();
1564 return dataBindings;
1568 bool IDataBindingsAccessor.HasDataBindings {
1570 if (dataBindings != null && dataBindings.Count > 0) {