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)
9 // Marek Habersack <mhabersack@novell.com>
12 // (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
13 // (C) 2004-2010 Novell, Inc. (http://www.novell.com)
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System.Collections;
38 using System.Collections.Generic;
39 using System.ComponentModel;
40 using System.ComponentModel.Design;
41 using System.ComponentModel.Design.Serialization;
42 using System.Globalization;
44 using System.Security.Permissions;
47 using System.Web.Configuration;
48 using System.Web.UI.Adapters;
49 using System.Web.UI.WebControls;
50 using System.Web.Util;
53 using System.Web.Routing;
56 namespace System.Web.UI
59 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
60 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
62 [DefaultProperty ("ID"), DesignerCategory ("Code"), ToolboxItemFilter ("System.Web.UI", ToolboxItemFilterType.Require)]
63 [ToolboxItem ("System.Web.UI.Design.WebControlToolboxItem, " + Consts.AssemblySystem_Design)]
64 [Designer ("System.Web.UI.Design.ControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
65 [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web,
66 "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design)]
69 public partial class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor, IUrlResolutionService, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
71 internal static readonly object DataBindingEvent = new object ();
72 internal static readonly object DisposedEvent = new object ();
73 internal static readonly object InitEvent = new object ();
74 internal static readonly object LoadEvent = new object ();
75 internal static readonly object PreRenderEvent = new object ();
76 internal static readonly object UnloadEvent = new object ();
77 internal static string [] defaultNameArray;
80 const int databinding_mask = 1;
81 const int disposed_mask = 1 << 1;
82 const int init_mask = 1 << 2;
83 const int load_mask = 1 << 3;
84 const int prerender_mask = 1 << 4;
85 const int unload_mask = 1 << 5;
89 static Dictionary <Type, bool> loadViewStateByIDCache;
90 bool? loadViewStateByID;
94 ControlCollection _controls;
95 Control _namingContainer;
100 EventHandlerList _events;
101 RenderMethod _renderMethodDelegate;
102 Hashtable _controlsCache;
105 DataBindingCollection dataBindings;
106 Hashtable pendingVS; // may hold unused viewstate data from child controls
107 TemplateControl _templateControl;
108 bool _isChildControlStateCleared;
109 string _templateSourceDirectory;
111 ViewStateMode viewStateMode;
112 ClientIDMode? clientIDMode;
113 ClientIDMode? effectiveClientIDMode;
114 Version renderingCompatibility;
115 bool? renderingCompatibilityOld;
119 const int ENABLE_VIEWSTATE = 1;
120 const int VISIBLE = 1 << 1;
121 const int AUTOID = 1 << 2;
122 const int CREATING_CONTROLS = 1 << 3;
123 const int BINDING_CONTAINER = 1 << 4;
124 const int AUTO_EVENT_WIREUP = 1 << 5;
125 const int IS_NAMING_CONTAINER = 1 << 6;
126 const int VISIBLE_CHANGED = 1 << 7;
127 const int TRACK_VIEWSTATE = 1 << 8;
128 const int CHILD_CONTROLS_CREATED = 1 << 9;
129 const int ID_SET = 1 << 10;
130 const int INITED = 1 << 11;
131 const int INITING = 1 << 12;
132 const int VIEWSTATE_LOADED = 1 << 13;
133 const int LOADED = 1 << 14;
134 const int PRERENDERED = 1 << 15;
135 const int ENABLE_THEMING = 1 << 16;
136 const int AUTOID_SET = 1 << 17;
137 const int REMOVED = 1 << 18;
142 defaultNameArray = new string [100];
143 for (int i = 0; i < 100; i++)
144 defaultNameArray [i] = String.Concat ("ctl", i.ToString ("D2"));
149 stateMask = ENABLE_VIEWSTATE | VISIBLE | AUTOID | BINDING_CONTAINER | AUTO_EVENT_WIREUP;
150 if (this is INamingContainer)
151 stateMask |= IS_NAMING_CONTAINER;
153 viewStateMode = ViewStateMode.Inherit;
157 ControlAdapter adapter;
158 bool did_adapter_lookup;
159 protected internal ControlAdapter Adapter {
161 if (!did_adapter_lookup) {
162 adapter = ResolveAdapter ();
164 adapter.control = this;
165 did_adapter_lookup = true;
171 string _appRelativeTemplateSourceDirectory = null;
173 [EditorBrowsable (EditorBrowsableState.Advanced)]
175 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
176 public string AppRelativeTemplateSourceDirectory {
178 if (_appRelativeTemplateSourceDirectory != null)
179 return _appRelativeTemplateSourceDirectory;
181 string tempSrcDir = null;
182 TemplateControl templateControl = TemplateControl;
183 if (templateControl != null) {
184 string templateVirtualPath = templateControl.AppRelativeVirtualPath;
185 if (!String.IsNullOrEmpty (templateVirtualPath))
186 tempSrcDir = VirtualPathUtility.GetDirectory (templateVirtualPath, false);
189 _appRelativeTemplateSourceDirectory = (tempSrcDir != null) ? tempSrcDir : VirtualPathUtility.ToAppRelative (TemplateSourceDirectory);
190 return _appRelativeTemplateSourceDirectory;
192 [EditorBrowsable (EditorBrowsableState.Never)]
194 _appRelativeTemplateSourceDirectory = value;
195 _templateSourceDirectory = null;
199 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
200 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
204 public Control BindingContainer {
206 Control container = NamingContainer;
207 if (container != null && container is INonBindingContainer || (stateMask & BINDING_CONTAINER) == 0)
208 container = container.BindingContainer;
214 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
216 [WebSysDescription ("An Identification of the control that is rendered.")]
217 public virtual string ClientID {
219 if (clientID != null)
222 clientID = GetClientID ();
224 clientID = UniqueID2ClientID (UniqueID);
233 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
234 public virtual Version RenderingCompatibility {
236 if (renderingCompatibility == null) {
237 var ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
238 renderingCompatibility = ps != null ? ps.ControlRenderingCompatibilityVersion : new Version (4, 0);
241 return renderingCompatibility;
245 renderingCompatibility = value;
246 renderingCompatibilityOld = null;
250 internal bool RenderingCompatibilityLessThan40 {
252 if (!renderingCompatibilityOld.HasValue)
253 renderingCompatibilityOld = RenderingCompatibility < new Version (4, 0);
255 return renderingCompatibilityOld.Value;
261 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
262 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
263 public Control DataItemContainer {
265 Control container = NamingContainer;
266 if (container == null)
269 if (container is IDataItemContainer)
272 return container.DataItemContainer;
278 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
279 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
280 public Control DataKeysContainer {
282 Control container = NamingContainer;
283 if (container == null)
286 if (container is IDataKeysControl)
289 return container.DataKeysContainer;
294 [DefaultValue (ClientIDMode.Inherit)]
295 public virtual ClientIDMode ClientIDMode {
297 if (!clientIDMode.HasValue)
298 return ClientIDMode.Inherit;
300 return clientIDMode.Value;
304 if (!clientIDMode.HasValue || clientIDMode.Value != value) {
305 ClearCachedClientID ();
306 ClearEffectiveClientIDMode ();
307 clientIDMode = value;
312 internal ClientIDMode EffectiveClientIDMode {
314 if (effectiveClientIDMode.HasValue)
315 return effectiveClientIDMode.Value;
317 ClientIDMode ret = ClientIDMode;
318 if (ret != ClientIDMode.Inherit) {
319 effectiveClientIDMode = ret;
323 // not sure about this, but it seems logical as INamingContainer is
324 // the top of the hierarchy and it should "reset" the mode.
325 Control container = NamingContainer;
326 if (container != null) {
327 effectiveClientIDMode = container.EffectiveClientIDMode;
328 return effectiveClientIDMode.Value;
331 var ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
332 effectiveClientIDMode = ps.ClientIDMode;
334 return effectiveClientIDMode.Value;
338 protected void ClearCachedClientID ()
344 for (int i = 0; i < _controls.Count; i++)
345 _controls [i].ClearCachedClientID ();
348 protected void ClearEffectiveClientIDMode ()
350 effectiveClientIDMode = null;
354 for (int i = 0; i < _controls.Count; i++)
355 _controls [i].ClearEffectiveClientIDMode ();
358 string GetClientID ()
360 switch (EffectiveClientIDMode) {
361 case ClientIDMode.AutoID:
362 return UniqueID2ClientID (UniqueID);
364 case ClientIDMode.Predictable:
366 return GeneratePredictableClientID ();
368 case ClientIDMode.Static:
373 throw new InvalidOperationException ("Unsupported ClientIDMode value.");
377 string GeneratePredictableClientID ()
380 bool haveMyID = !String.IsNullOrEmpty (myID);
381 char separator = ClientIDSeparator;
383 var sb = new StringBuilder ();
384 Control container = NamingContainer;
385 if (this is INamingContainer && !haveMyID) {
386 if (container != null)
391 if (container != null && container != Page) {
392 string containerID = container.ID;
393 if (!String.IsNullOrEmpty (containerID)) {
394 sb.Append (container.GetClientID ());
395 sb.Append (separator);
397 sb.Append (container.GeneratePredictableClientID ());
399 sb.Append (separator);
404 if (this is INamingContainer || !AutoID)
407 int length = sb.Length;
408 if (length > 0 && sb [length - 1] == separator)
409 sb.Length = length - 1;
412 return sb.ToString ();
416 IDataItemContainer dataItemContainer = DataItemContainer as IDataItemContainer;
417 if (dataItemContainer == null)
418 return sb.ToString ();
420 IDataKeysControl dataKeysContainer = DataKeysContainer as IDataKeysControl;
421 GetDataBoundControlFieldValue (sb, separator, dataItemContainer, dataKeysContainer);
423 return sb.ToString ();
426 void GetDataBoundControlFieldValue (StringBuilder sb, char separator, IDataItemContainer dataItemContainer, IDataKeysControl dataKeysContainer)
428 if (dataItemContainer is IDataBoundItemControl)
431 int index = dataItemContainer.DisplayIndex;
432 if (dataKeysContainer == null) {
434 sb.Append (separator);
440 string[] suffixes = dataKeysContainer.ClientIDRowSuffix;
441 DataKeyArray keys = dataKeysContainer.ClientIDRowSuffixDataKeys;
442 if (keys == null || suffixes == null || suffixes.Length == 0) {
443 sb.Append (separator);
449 DataKey key = keys [index];
450 foreach (string suffix in suffixes) {
451 sb.Append (separator);
452 value = key != null ? key [suffix] : null;
455 sb.Append (value.ToString ());
459 internal string UniqueID2ClientID (string uniqueId)
461 if (String.IsNullOrEmpty (uniqueId))
464 return uniqueId.Replace (IdSeparator, ClientIDSeparator);
467 protected char ClientIDSeparator {
472 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
474 [WebSysDescription ("The child controls of this control.")]
475 public virtual ControlCollection Controls { //DIT
477 if (_controls == null)
478 _controls = CreateControlCollection ();
483 [MonoTODO ("revisit once we have a real design strategy")]
484 protected internal bool DesignMode {
485 get { return false; }
488 [DefaultValue (true), WebCategory ("Behavior")]
489 [WebSysDescription ("An Identification of the control that is rendered.")]
491 public virtual bool EnableViewState {
492 get { return ((stateMask & ENABLE_VIEWSTATE) != 0); }
493 set { SetMask (ENABLE_VIEWSTATE, value); }
496 [MergableProperty (false), ParenthesizePropertyName (true)]
497 [WebSysDescription ("The name of the control that is rendered.")]
498 [Filterable (false), Themeable (false)]
499 public virtual string ID {
500 get { return (((stateMask & ID_SET) != 0) ? _userId : null); }
503 if (value != null && value.Length == 0)
512 protected internal bool IsChildControlStateCleared {
513 get { return _isChildControlStateCleared; }
516 protected bool LoadViewStateByID {
518 if (loadViewStateByID == null)
519 loadViewStateByID = IsLoadViewStateByID ();
521 return (bool)loadViewStateByID;
525 protected internal bool IsViewStateEnabled {
527 for (Control control = this; control != null; control = control.Parent) {
528 if (!control.EnableViewState)
531 ViewStateMode vsm = control.ViewStateMode;
532 if (vsm != ViewStateMode.Inherit)
533 return vsm == ViewStateMode.Enabled;
541 protected char IdSeparator {
545 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
547 [WebSysDescription ("The container that this control is part of. The control's name has to be unique within the container.")]
551 public virtual Control NamingContainer {
553 if (_namingContainer == null && _parent != null) {
554 if ((_parent.stateMask & IS_NAMING_CONTAINER) == 0)
555 _namingContainer = _parent.NamingContainer;
557 _namingContainer = _parent;
560 return _namingContainer;
564 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
566 [WebSysDescription ("The webpage that this control resides on.")]
568 public virtual Page Page { //DIT
571 if (NamingContainer != null)
572 _page = NamingContainer.Page;
573 else if (Parent != null)
579 set { _page = value; }
582 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
584 [WebSysDescription ("The parent control of this control.")]
588 public virtual Control Parent { //DIT
589 get { return _parent; }
592 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
593 [EditorBrowsable (EditorBrowsableState.Advanced), Browsable (false)]
594 [WebSysDescription ("The site this control is part of.")]
595 public ISite Site { //DIT
596 get { return _site; }
597 set { _site = value; }
601 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
605 public TemplateControl TemplateControl {
606 get { return TemplateControlInternal; }
608 [EditorBrowsable (EditorBrowsableState.Never)]
609 set { _templateControl = value; }
612 internal virtual TemplateControl TemplateControlInternal {
614 if (_templateControl != null)
615 return _templateControl;
617 return _parent.TemplateControl;
623 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
625 [WebSysDescription ("A virtual directory containing the parent of the control.")]
626 public virtual string TemplateSourceDirectory {
628 if (_templateSourceDirectory == null) {
629 TemplateControl tc = TemplateControl;
632 HttpContext ctx = Context;
634 _templateSourceDirectory = VirtualPathUtility.GetDirectory (ctx.Request.CurrentExecutionFilePath);
635 } else if (tc != this)
636 _templateSourceDirectory = tc.TemplateSourceDirectory;
638 if (_templateSourceDirectory == null && this is TemplateControl) {
639 string path = ((TemplateControl) this).AppRelativeVirtualPath;
642 string ret = VirtualPathUtility.GetDirectory (VirtualPathUtility.ToAbsolute (path));
643 int len = ret.Length;
646 if (ret [--len] == '/')
647 _templateSourceDirectory = ret.Substring (0, len);
649 _templateSourceDirectory = String.Empty;
651 if (_templateSourceDirectory == null)
652 _templateSourceDirectory = String.Empty;
655 return _templateSourceDirectory;
660 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
662 [WebSysDescription ("The unique ID of the control.")]
663 public virtual string UniqueID {
665 if (uniqueID != null)
668 Control container = NamingContainer;
669 if (container == null)
673 string prefix = container.UniqueID;
674 if (container == Page || prefix == null) {
677 if (getFacesContext () != null)
678 uniqueID = getFacesContext ().getExternalContext ().encodeNamespace (uniqueID);
683 uniqueID = prefix + IdSeparator + _userId;
688 void SetMask (int m, bool val) {
695 [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
696 [WebSysDescription ("Visiblity state of the control.")]
697 public virtual bool Visible {
699 if ((stateMask & VISIBLE) == 0)
703 return _parent.Visible;
709 if ((value && (stateMask & VISIBLE) == 0) ||
710 (!value && (stateMask & VISIBLE) != 0)) {
711 if (IsTrackingViewState)
712 stateMask |= VISIBLE_CHANGED;
715 SetMask (VISIBLE, value);
719 protected bool ChildControlsCreated {
720 get { return ((stateMask & CHILD_CONTROLS_CREATED) != 0); }
722 if (value == false && (stateMask & CHILD_CONTROLS_CREATED) != 0) {
723 ControlCollection cc = Controls;
728 SetMask (CHILD_CONTROLS_CREATED, value);
733 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
734 protected internal virtual HttpContext Context { //DIT
740 return HttpContext.Current;
744 protected EventHandlerList Events {
747 _events = new EventHandlerList ();
752 protected bool HasChildViewState {
753 get { return (pendingVS != null && pendingVS.Count > 0); }
756 protected bool IsTrackingViewState {
757 get { return ((stateMask & TRACK_VIEWSTATE) != 0); }
761 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
762 [WebSysDescription ("ViewState")]
763 protected virtual StateBag ViewState {
765 if (_viewState == null)
766 _viewState = new StateBag (ViewStateIgnoresCase);
768 if (IsTrackingViewState)
769 _viewState.TrackViewState ();
776 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
777 protected virtual bool ViewStateIgnoresCase {
778 get { return false; }
781 internal bool AutoEventWireup {
782 get { return (stateMask & AUTO_EVENT_WIREUP) != 0; }
783 set { SetMask (AUTO_EVENT_WIREUP, value); }
786 internal void SetBindingContainer (bool isBC)
788 SetMask (BINDING_CONTAINER, isBC);
791 internal void ResetChildNames ()
793 ResetChildNames (-1);
796 internal void ResetChildNames (int value)
801 defaultNumberID = value;
804 internal int GetDefaultNumberID ()
806 return defaultNumberID;
809 string GetDefaultName ()
812 if (defaultNumberID > 99)
813 defaultName = "ctl" + defaultNumberID++;
815 defaultName = defaultNameArray [defaultNumberID++];
819 void NullifyUniqueID ()
823 ClearCachedClientID ();
830 for (int i = 0; i < _controls.Count; i++)
831 _controls [i].NullifyUniqueID ();
834 bool IsLoadViewStateByID ()
836 if (loadViewStateByIDCache == null)
837 loadViewStateByIDCache = new Dictionary <Type, bool> ();
840 Type myType = GetType ();
841 if (loadViewStateByIDCache.TryGetValue (myType, out ret))
844 System.ComponentModel.AttributeCollection attrs = TypeDescriptor.GetAttributes (myType);
848 foreach (Attribute attr in attrs) {
849 if (attr is ViewStateModeByIdAttribute) {
856 loadViewStateByIDCache.Add (myType, ret);
860 protected internal virtual void AddedControl (Control control, int index)
862 ResetControlsCache ();
864 /* Ensure the control don't have more than 1 parent */
865 if (control._parent != null)
866 control._parent.Controls.Remove (control);
868 control._parent = this;
869 Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer;
871 if ((stateMask & (INITING | INITED)) != 0) {
872 control.InitRecursive (nc);
873 control.SetMask (REMOVED, false);
875 control.SetNamingContainer (nc);
876 control.SetMask (REMOVED, false);
880 if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) {
881 if (pendingVS != null) {
883 bool byId = LoadViewStateByID;
892 vs = pendingVS [index];
897 pendingVS.Remove (id);
899 pendingVS.Remove (index);
901 if (pendingVS.Count == 0)
904 control.LoadViewStateRecursive (vs);
909 if ((stateMask & LOADED) != 0)
910 control.LoadRecursive ();
912 if ((stateMask & PRERENDERED) != 0)
913 control.PreRenderRecursiveInternal ();
916 void SetNamingContainer (Control nc)
919 _namingContainer = nc;
925 protected virtual void AddParsedSubObject (object obj) //DIT
927 Control c = obj as Control;
932 [EditorBrowsable (EditorBrowsableState.Advanced)]
933 public virtual void ApplyStyleSheetSkin (Page page)
938 if (!EnableTheming) /* this enough? */
941 /* apply the style sheet skin here */
942 if (page.StyleSheetPageTheme != null) {
943 ControlSkin cs = page.StyleSheetPageTheme.GetControlSkin (GetType (), SkinID);
950 protected void BuildProfileTree (string parentId, bool calcViewState)
954 protected void ClearChildControlState ()
956 _isChildControlStateCleared = true;
959 protected void ClearChildState ()
961 ClearChildViewState ();
962 ClearChildControlState ();
965 protected void ClearChildViewState ()
970 protected internal virtual void CreateChildControls () //DIT
974 protected virtual ControlCollection CreateControlCollection () //DIT
976 return new ControlCollection (this);
979 protected virtual void EnsureChildControls ()
981 if (ChildControlsCreated == false && (stateMask & CREATING_CONTROLS) == 0) {
982 stateMask |= CREATING_CONTROLS;
984 Adapter.CreateChildControls ();
986 CreateChildControls ();
987 ChildControlsCreated = true;
988 stateMask &= ~CREATING_CONTROLS;
992 void EnsureIDInternal ()
997 _userId = NamingContainer.GetDefaultName ();
998 SetMask (AUTOID_SET, true);
1001 protected void EnsureID ()
1003 if (NamingContainer == null)
1005 EnsureIDInternal ();
1006 SetMask (ID_SET, true);
1009 protected bool HasEvents ()
1011 return _events != null;
1014 void ResetControlsCache ()
1016 _controlsCache = null;
1018 if ((this.stateMask & IS_NAMING_CONTAINER) == 0 && Parent != null)
1019 Parent.ResetControlsCache ();
1022 Hashtable InitControlsCache ()
1024 if (_controlsCache != null)
1025 return _controlsCache;
1027 if ((this.stateMask & IS_NAMING_CONTAINER) != 0 || Parent == null)
1028 //LAMESPEC: MS' docs don't mention it, but FindControl is case insensitive.
1029 _controlsCache = new Hashtable (StringComparer.OrdinalIgnoreCase);
1031 _controlsCache = Parent.InitControlsCache ();
1033 return _controlsCache;
1036 void EnsureControlsCache ()
1038 if (_controlsCache != null)
1041 InitControlsCache ();
1043 FillControlCache (_controls);
1046 void FillControlCache (ControlCollection controls)
1048 if (controls == null || controls.Count == 0)
1051 foreach (Control c in controls) {
1053 if (c._userId != null)
1054 _controlsCache.Add (c._userId, c);
1055 } catch (ArgumentException) {
1056 throw new HttpException (
1057 "Multiple controls with the same ID '" +
1059 "' were found. FindControl requires that controls have unique IDs. ");
1062 if ((c.stateMask & IS_NAMING_CONTAINER) == 0 && c.HasControls ())
1063 FillControlCache (c.Controls);
1067 protected bool IsLiteralContent ()
1069 if (_controls != null && _controls.Count == 1 && _controls [0] is LiteralControl)
1075 [WebSysDescription ("")]
1076 public virtual Control FindControl (string id)
1078 return FindControl (id, 0);
1081 Control LookForControlByName (string id)
1083 EnsureControlsCache ();
1084 return (Control) _controlsCache [id];
1087 protected virtual Control FindControl (string id, int pathOffset)
1089 EnsureChildControls ();
1090 Control namingContainer = null;
1091 if ((stateMask & IS_NAMING_CONTAINER) == 0) {
1092 namingContainer = NamingContainer;
1093 if (namingContainer == null)
1096 return namingContainer.FindControl (id, pathOffset);
1099 if (!HasControls ())
1102 int separatorIdx = id.IndexOf (IdSeparator, pathOffset);
1103 if (separatorIdx == -1) {
1104 // If there are no separators in the id, we must first check whether
1105 // any direct descendant control with that id exists before
1106 // attempting to look in our naming container
1107 Control ctl = LookForControlByName (pathOffset > 0 ? id.Substring (pathOffset) : id);
1111 if (pathOffset == 0) {
1112 namingContainer = NamingContainer;
1113 if (namingContainer != null) {
1114 ctl = namingContainer.FindControl (id);
1122 string idfound = id.Substring (pathOffset, separatorIdx - pathOffset);
1123 namingContainer = LookForControlByName (idfound);
1124 if (namingContainer == null)
1127 return namingContainer.FindControl (id, separatorIdx + 1);
1130 protected virtual void LoadViewState (object savedState)
1132 if (savedState != null) {
1133 ViewState.LoadViewState (savedState);
1134 object o = ViewState ["Visible"];
1136 SetMask (VISIBLE, (bool) o);
1137 stateMask |= VISIBLE_CHANGED;
1142 // [MonoTODO("Secure?")]
1143 protected string MapPathSecure (string virtualPath)
1145 string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
1146 return Context.Request.MapPath (combined);
1149 protected virtual bool OnBubbleEvent (object source, EventArgs args) //DIT
1152 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1153 string type_name = null;
1154 if (trace != null) {
1155 type_name = GetType ().Name;
1156 trace.Write ("control", String.Concat ("OnBubbleEvent ", _userId, " ", type_name));
1162 protected virtual void OnDataBinding (EventArgs e)
1164 if ((event_mask & databinding_mask) != 0) {
1165 EventHandler eh = (EventHandler) (_events [DataBindingEvent]);
1168 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1169 string type_name = null;
1170 if (trace != null) {
1171 type_name = GetType ().Name;
1172 trace.Write ("control", String.Concat ("OnDataBinding ", _userId, " ", type_name));
1180 protected internal virtual void OnInit (EventArgs e)
1182 if ((event_mask & init_mask) != 0) {
1183 EventHandler eh = (EventHandler) (_events [InitEvent]);
1186 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1187 string type_name = null;
1188 if (trace != null) {
1189 type_name = GetType ().Name;
1190 trace.Write ("control", String.Concat ("OnInit ", _userId, " ", type_name));
1198 protected internal virtual void OnLoad (EventArgs e)
1200 if ((event_mask & load_mask) != 0) {
1201 EventHandler eh = (EventHandler) (_events [LoadEvent]);
1204 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1205 string type_name = null;
1206 if (trace != null) {
1207 type_name = GetType ().Name;
1208 trace.Write ("control", String.Concat ("OnLoad ", _userId, " ", type_name));
1216 protected internal virtual void OnPreRender (EventArgs e)
1218 if ((event_mask & prerender_mask) != 0) {
1219 EventHandler eh = (EventHandler) (_events [PreRenderEvent]);
1222 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1223 string type_name = null;
1224 if (trace != null) {
1225 type_name = GetType ().Name;
1226 trace.Write ("control", String.Concat ("OnPreRender ", _userId, " ", type_name));
1234 protected internal virtual void OnUnload (EventArgs e)
1236 if ((event_mask & unload_mask) != 0) {
1237 EventHandler eh = (EventHandler) (_events [UnloadEvent]);
1240 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1241 string type_name = null;
1242 if (trace != null) {
1243 type_name = GetType ().Name;
1244 trace.Write ("control", String.Concat ("OnUnload ", _userId, " ", type_name));
1252 protected internal Stream OpenFile (string path)
1255 string filePath = Context.Server.MapPath (path);
1256 return File.OpenRead (filePath);
1258 catch (UnauthorizedAccessException) {
1259 throw new HttpException ("Access to the specified file was denied.");
1263 internal string GetPhysicalFilePath (string virtualPath)
1267 if (VirtualPathUtility.IsAbsolute (virtualPath))
1268 return page != null ? page.MapPath (virtualPath) : Context.Server.MapPath (virtualPath);
1270 // We need to determine whether one of our parents is a
1271 // master page. If so, we need to map the path
1272 // relatively to the master page and not our containing
1273 // page/control. This is necessary for cases when a
1274 // relative path is used in a control placed in a master
1275 // page and the master page is referenced from a
1276 // location other than its own. In such cases MS.NET looks
1277 // for the file in the directory where the master page
1280 // An example of where it is needed is at
1282 // http://quickstarts.asp.net/QuickStartv20/aspnet/samples/masterpages/masterpages_cs/pages/default.aspx
1284 MasterPage master = null;
1285 Control ctrl = Parent;
1287 while (ctrl != null) {
1288 if (ctrl is MasterPage) {
1289 master = ctrl as MasterPage;
1297 path = VirtualPathUtility.Combine (master.TemplateSourceDirectory + "/", virtualPath);
1299 path = VirtualPathUtility.Combine (TemplateSourceDirectory + "/", virtualPath);
1301 return page != null ? page.MapPath (path) : Context.Server.MapPath (path);
1304 protected void RaiseBubbleEvent (object source, EventArgs args)
1309 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1310 string type_name = null;
1311 if (trace != null) {
1312 type_name = GetType ().Name;
1313 trace.Write ("control", String.Concat ("RaiseBubbleEvent ", _userId, " ", type_name));
1316 if (c.OnBubbleEvent (source, args)) {
1319 trace.Write ("control", String.Concat ("End RaiseBubbleEvent (false) ", _userId, " ", type_name));
1325 trace.Write ("control", String.Concat ("End RaiseBubbleEvent (true) ", _userId, " ", type_name));
1331 protected internal virtual void Render (HtmlTextWriter writer) //DIT
1333 RenderChildren (writer);
1336 protected internal virtual void RenderChildren (HtmlTextWriter writer) //DIT
1338 if (_renderMethodDelegate != null) {
1339 _renderMethodDelegate (writer, this);
1343 if (_controls == null)
1346 int len = _controls.Count;
1348 for (int i = 0; i < len; i++) {
1352 ControlAdapter tmp = c.Adapter;
1354 c.RenderControl (writer, tmp);
1356 c.RenderControl (writer);
1360 protected virtual ControlAdapter ResolveAdapter ()
1362 HttpContext context = Context;
1364 if (context == null)
1367 if (!context.Request.BrowserMightHaveAdapters)
1370 // Search up the type hierarchy until we find a control with an adapter.
1371 IDictionary typeMap = context.Request.Browser.Adapters;
1372 Type controlType = GetType ();
1373 Type adapterType = (Type)typeMap [controlType];
1374 while (adapterType == null && controlType != typeof (Control)) {
1375 controlType = controlType.BaseType;
1376 adapterType = (Type)typeMap [controlType];
1379 ControlAdapter a = null;
1380 if (adapterType != null)
1381 a = (ControlAdapter)Activator.CreateInstance (adapterType);
1385 protected virtual object SaveViewState ()
1387 if ((stateMask & VISIBLE_CHANGED) != 0) {
1388 ViewState ["Visible"] = (stateMask & VISIBLE) != 0;
1389 } else if (_viewState == null) {
1393 return _viewState.SaveViewState ();
1396 protected virtual void TrackViewState ()
1398 if (_viewState != null)
1399 _viewState.TrackViewState ();
1401 stateMask |= TRACK_VIEWSTATE;
1404 public virtual void Dispose ()
1406 if ((event_mask & disposed_mask) != 0) {
1407 EventHandler eh = (EventHandler) (_events [DisposedEvent]);
1409 eh (this, EventArgs.Empty);
1413 [WebCategory ("FIXME")]
1414 [WebSysDescription ("Raised when the contols databound properties are evaluated.")]
1415 public event EventHandler DataBinding {
1417 event_mask |= databinding_mask;
1418 Events.AddHandler (DataBindingEvent, value);
1420 remove { Events.RemoveHandler (DataBindingEvent, value); }
1423 [WebSysDescription ("Raised when the contol is disposed.")]
1424 public event EventHandler Disposed {
1426 event_mask |= disposed_mask;
1427 Events.AddHandler (DisposedEvent, value);
1429 remove { Events.RemoveHandler (DisposedEvent, value); }
1432 [WebSysDescription ("Raised when the page containing the control is initialized.")]
1433 public event EventHandler Init {
1435 event_mask |= init_mask;
1436 Events.AddHandler (InitEvent, value);
1438 remove { Events.RemoveHandler (InitEvent, value); }
1441 [WebSysDescription ("Raised after the page containing the control has been loaded.")]
1442 public event EventHandler Load {
1444 event_mask |= load_mask;
1445 Events.AddHandler (LoadEvent, value);
1447 remove { Events.RemoveHandler (LoadEvent, value); }
1450 [WebSysDescription ("Raised before the page containing the control is rendered.")]
1451 public event EventHandler PreRender {
1453 event_mask |= prerender_mask;
1454 Events.AddHandler (PreRenderEvent, value);
1456 remove { Events.RemoveHandler (PreRenderEvent, value); }
1459 [WebSysDescription ("Raised when the page containing the control is unloaded.")]
1460 public event EventHandler Unload {
1462 event_mask |= unload_mask;
1463 Events.AddHandler (UnloadEvent, value);
1465 remove { Events.RemoveHandler (UnloadEvent, value); }
1468 public virtual void DataBind () //DIT
1473 protected virtual void DataBindChildren ()
1475 if (!HasControls ())
1478 int len = _controls != null ? _controls.Count : 0;
1479 for (int i = 0; i < len; i++) {
1480 Control c = _controls [i];
1485 public virtual bool HasControls ()
1487 return (_controls != null && _controls.Count > 0);
1490 public virtual void RenderControl (HtmlTextWriter writer)
1492 if (this.adapter != null) {
1493 RenderControl (writer, this.adapter);
1497 if ((stateMask & VISIBLE) != 0) {
1498 HttpContext ctx = Context;
1499 TraceContext trace = (ctx != null) ? ctx.Trace : null;
1501 if ((trace != null) && trace.IsEnabled)
1502 pos = ctx.Response.GetOutputByteCount ();
1505 if ((trace != null) && trace.IsEnabled) {
1506 int size = ctx.Response.GetOutputByteCount () - pos;
1507 trace.SaveSize (this, size >= 0 ? size : 0);
1512 protected void RenderControl (HtmlTextWriter writer, ControlAdapter adapter)
1514 if ((stateMask & VISIBLE) != 0) {
1515 adapter.BeginRender (writer);
1516 adapter.Render (writer);
1517 adapter.EndRender (writer);
1521 public string ResolveUrl (string relativeUrl)
1523 if (relativeUrl == null)
1524 throw new ArgumentNullException ("relativeUrl");
1526 if (relativeUrl == String.Empty)
1529 if (VirtualPathUtility.IsAbsolute (relativeUrl))
1532 if (relativeUrl [0] == '#')
1535 string ts = AppRelativeTemplateSourceDirectory;
1536 HttpContext ctx = Context;
1537 HttpResponse resp = ctx != null ? ctx.Response : null;
1538 if (ts == null || ts.Length == 0 || resp == null || relativeUrl.IndexOf (':') >= 0)
1541 if (!VirtualPathUtility.IsAppRelative (relativeUrl))
1542 relativeUrl = VirtualPathUtility.Combine (VirtualPathUtility.AppendTrailingSlash (ts), relativeUrl);
1544 return resp.ApplyAppPathModifier (relativeUrl);
1548 public string ResolveClientUrl (string relativeUrl)
1550 if (relativeUrl == null)
1551 throw new ArgumentNullException ("relativeUrl");
1553 if (relativeUrl.Length == 0)
1554 return String.Empty;
1557 relativeUrl = ResolveClientUrlInternal (relativeUrl);
1559 javax.faces.context.FacesContext faces = getFacesContext ();
1564 if (relativeUrl.IndexOf (':') >= 0)
1565 url = ResolveAppRelativeFromFullPath (relativeUrl);
1566 else if (VirtualPathUtility.IsAbsolute (relativeUrl))
1567 url = VirtualPathUtility.ToAppRelative (relativeUrl);
1569 return faces.getApplication ().getViewHandler ().getResourceURL (faces, relativeUrl);
1571 if (VirtualPathUtility.IsAppRelative (url)) {
1572 url = url.Substring (1);
1573 url = url.Length == 0 ? "/" : url;
1574 return faces.getApplication ().getViewHandler ().getResourceURL (faces, url);
1579 string ResolveClientUrlInternal (string relativeUrl) {
1580 if (relativeUrl.StartsWith (J2EE.J2EEConsts.ACTION_URL_PREFIX, StringComparison.Ordinal))
1581 return CreateActionUrl (relativeUrl.Substring (J2EE.J2EEConsts.ACTION_URL_PREFIX.Length));
1583 if (relativeUrl.StartsWith (J2EE.J2EEConsts.RENDER_URL_PREFIX, StringComparison.Ordinal))
1584 return ResolveClientUrl (relativeUrl.Substring (J2EE.J2EEConsts.RENDER_URL_PREFIX.Length));
1587 if (VirtualPathUtility.IsAbsolute (relativeUrl) || relativeUrl.IndexOf (':') >= 0)
1590 HttpContext context = Context;
1591 HttpRequest req = context != null ? context.Request : null;
1593 string templateSourceDirectory = TemplateSourceDirectory;
1594 if (templateSourceDirectory == null || templateSourceDirectory.Length == 0)
1597 string basePath = req.ClientFilePath;
1599 if (basePath.Length > 1 && basePath [basePath.Length - 1] != '/')
1600 basePath = VirtualPathUtility.GetDirectory (basePath, false);
1602 if (VirtualPathUtility.IsAppRelative (relativeUrl))
1603 return VirtualPathUtility.MakeRelative (basePath, relativeUrl);
1605 string templatePath = VirtualPathUtility.AppendTrailingSlash (templateSourceDirectory);
1607 if (basePath.Length == templatePath.Length && String.CompareOrdinal (basePath, templatePath) == 0)
1610 relativeUrl = VirtualPathUtility.Combine (templatePath, relativeUrl);
1611 return VirtualPathUtility.MakeRelative (basePath, relativeUrl);
1616 internal bool HasRenderMethodDelegate ()
1618 return _renderMethodDelegate != null;
1621 [EditorBrowsable (EditorBrowsableState.Advanced)]
1622 public void SetRenderMethodDelegate (RenderMethod renderMethod) //DIT
1624 _renderMethodDelegate = renderMethod;
1627 internal void LoadRecursive ()
1630 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1631 string type_name = null;
1632 if (trace != null) {
1633 type_name = GetType ().Name;
1634 trace.Write ("control", String.Concat ("LoadRecursive ", _userId, " ", type_name));
1637 if ((stateMask & LOADED) == 0) {
1638 if (Adapter != null)
1639 Adapter.OnLoad (EventArgs.Empty);
1641 OnLoad (EventArgs.Empty);
1643 int ccount = _controls != null ? _controls.Count : 0;
1644 for (int i = 0; i < ccount; i++) {
1645 Control c = _controls [i];
1651 trace.Write ("control", String.Concat ("End LoadRecursive ", _userId, " ", type_name));
1653 stateMask |= LOADED;
1656 internal void UnloadRecursive (Boolean dispose)
1659 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1660 string type_name = null;
1661 if (trace != null) {
1662 type_name = GetType ().Name;
1663 trace.Write ("control", String.Concat ("UnloadRecursive ", _userId, " ", type_name));
1666 int ccount = _controls != null ? _controls.Count : 0;
1667 for (int i = 0; i < ccount; i++) {
1668 Control c = _controls [i];
1669 c.UnloadRecursive (dispose);
1674 trace.Write ("control", String.Concat ("End UnloadRecursive ", _userId, " ", type_name));
1676 ControlAdapter tmp = Adapter;
1678 tmp.OnUnload (EventArgs.Empty);
1680 OnUnload (EventArgs.Empty);
1685 internal void PreRenderRecursiveInternal ()
1691 SetMask (VISIBLE, true);
1692 EnsureChildControls ();
1694 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1695 string type_name = null;
1696 if (trace != null) {
1697 type_name = GetType ().Name;
1698 trace.Write ("control", String.Concat ("PreRenderRecursive ", _userId, " ", type_name));
1701 if (Adapter != null)
1702 Adapter.OnPreRender (EventArgs.Empty);
1704 OnPreRender (EventArgs.Empty);
1705 if (!HasControls ())
1708 int len = _controls != null ? _controls.Count : 0;
1709 for (int i = 0; i < len; i++) {
1710 Control c = _controls [i];
1711 c.PreRenderRecursiveInternal ();
1715 trace.Write ("control", String.Concat ("End PreRenderRecursive ", _userId, " ", type_name));
1718 SetMask (VISIBLE, false);
1720 stateMask |= PRERENDERED;
1727 void InitRecursive (Control namingContainer)
1730 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1731 string type_name = null;
1732 if (trace != null) {
1733 type_name = GetType ().Name;
1734 trace.Write ("control", String.Concat ("InitRecursive ", _userId, " ", type_name));
1737 SetNamingContainer (namingContainer);
1739 if (HasControls ()) {
1740 if ((stateMask & IS_NAMING_CONTAINER) != 0)
1741 namingContainer = this;
1743 int len = _controls != null ? _controls.Count : 0;
1744 for (int i = 0; i < len; i++) {
1745 Control c = _controls [i];
1746 c.InitRecursive (namingContainer);
1750 if ((stateMask & REMOVED) == 0 && (stateMask & INITED) != INITED) {
1751 stateMask |= INITING;
1753 ControlAdapter tmp = Adapter;
1755 tmp.OnInit (EventArgs.Empty);
1757 OnInit (EventArgs.Empty);
1759 stateMask |= INITED;
1760 stateMask &= ~INITING;
1765 trace.Write ("control", String.Concat ("End InitRecursive ", _userId, " ", type_name));
1769 internal object SaveViewStateRecursive ()
1771 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1773 string type_name = null;
1774 if (trace != null) {
1775 type_name = GetType ().Name;
1776 trace.Write ("control", String.Concat ("SaveViewStateRecursive ", _userId, " ", type_name));
1780 ArrayList controlStates = null;
1781 bool byId = LoadViewStateByID;
1782 if (HasControls ()) {
1783 int len = _controls != null ? _controls.Count : 0;
1784 for (int i = 0; i < len; i++) {
1785 Control ctrl = _controls [i];
1786 object ctrlState = ctrl.SaveViewStateRecursive ();
1787 if (ctrlState == null)
1790 if (controlStates == null)
1791 controlStates = new ArrayList ();
1794 controlStates.Add (new Pair (ctrl.ID, ctrlState));
1796 controlStates.Add (new Pair (i, ctrlState));
1800 object thisAdapterViewState = null;
1801 if (Adapter != null)
1802 thisAdapterViewState = Adapter.SaveAdapterViewState ();
1804 object thisState = null;
1806 if (IsViewStateEnabled)
1807 thisState = SaveViewState ();
1809 if (thisState == null && controlStates == null) {
1810 if (trace != null) {
1812 trace.Write ("control", "End SaveViewStateRecursive " + _userId + " " + type_name + " saved nothing");
1814 trace.SaveViewState (this, null);
1819 if (trace != null) {
1821 trace.Write ("control", "End SaveViewStateRecursive " + _userId + " " + type_name + " saved a Triplet");
1823 trace.SaveViewState (this, thisState);
1825 thisState = new object[] { thisState, thisAdapterViewState };
1826 return new Pair (thisState, controlStates);
1829 internal void LoadViewStateRecursive (object savedState)
1831 if (savedState == null)
1835 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1836 string type_name = null;
1837 if (trace != null) {
1838 type_name = GetType ().Name;
1839 trace.Write ("control", String.Concat ("LoadViewStateRecursive ", _userId, " ", type_name));
1842 Pair savedInfo = (Pair) savedState;
1843 object[] controlAndAdapterViewStates = (object [])savedInfo.First;
1844 if (Adapter != null)
1845 Adapter.LoadAdapterViewState (controlAndAdapterViewStates [1]);
1846 LoadViewState (controlAndAdapterViewStates [0]);
1848 ArrayList controlStates = savedInfo.Second as ArrayList;
1849 if (controlStates == null)
1852 int nControls = controlStates.Count;
1853 bool byId = LoadViewStateByID;
1854 for (int i = 0; i < nControls; i++) {
1855 Pair p = controlStates [i] as Pair;
1860 string id = (string)p.First;
1863 foreach (Control c in Controls) {
1867 c.LoadViewStateRecursive (p.Second);
1873 if (pendingVS == null)
1874 pendingVS = new Hashtable ();
1875 pendingVS [id] = p.Second;
1878 int k = (int) p.First;
1879 if (k < Controls.Count) {
1880 Control c = Controls [k];
1881 c.LoadViewStateRecursive (p.Second);
1883 if (pendingVS == null)
1884 pendingVS = new Hashtable ();
1886 pendingVS [k] = p.Second;
1893 trace.Write ("control", String.Concat ("End LoadViewStateRecursive ", _userId, " ", type_name));
1895 stateMask |= VIEWSTATE_LOADED;
1898 internal ControlSkin controlSkin;
1900 internal void ApplyTheme ()
1903 TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
1904 string type_name = null;
1905 if (trace != null) {
1906 type_name = GetType ().Name;
1907 trace.Write ("control", String.Concat ("ApplyThemeRecursive ", _userId, " ", type_name));
1911 if (page != null && page.PageTheme != null && EnableTheming) {
1912 ControlSkin controlSkin = page.PageTheme.GetControlSkin (GetType (), SkinID);
1913 if (controlSkin != null)
1914 controlSkin.ApplySkin (this);
1919 trace.Write ("control", String.Concat ("End ApplyThemeRecursive ", _userId, " ", type_name));
1923 internal bool AutoID {
1924 get { return (stateMask & AUTOID) != 0; }
1926 if (value == false && (stateMask & IS_NAMING_CONTAINER) != 0)
1929 SetMask (AUTOID, value);
1933 protected internal virtual void RemovedControl (Control control)
1935 control.UnloadRecursive (false);
1936 control._parent = null;
1937 control._page = null;
1938 control._namingContainer = null;
1939 if ((control.stateMask & AUTOID_SET) != 0) {
1940 control._userId = null;
1941 control.SetMask (ID_SET, false);
1943 control.NullifyUniqueID ();
1944 control.SetMask (REMOVED, true);
1945 ResetControlsCache ();
1948 string skinId = string.Empty;
1949 bool _enableTheming = true;
1953 [DefaultValue (true)]
1954 public virtual bool EnableTheming {
1956 if ((stateMask & ENABLE_THEMING) != 0)
1957 return _enableTheming;
1959 if (_parent != null)
1960 return _parent.EnableTheming;
1965 SetMask (ENABLE_THEMING, true);
1966 _enableTheming = value;
1972 [Filterable (false)]
1973 public virtual string SkinID {
1974 get { return skinId; }
1975 set { skinId = value; }
1978 ControlBuilder IControlBuilderAccessor.ControlBuilder {
1979 get { throw new NotImplementedException (); }
1982 IDictionary IControlDesignerAccessor.GetDesignModeState ()
1984 throw new NotImplementedException ();
1987 void IControlDesignerAccessor.SetDesignModeState (IDictionary designData)
1989 SetDesignModeState (designData);
1992 void IControlDesignerAccessor.SetOwnerControl (Control control)
1994 throw new NotImplementedException ();
1997 IDictionary IControlDesignerAccessor.UserData {
1998 get { throw new NotImplementedException (); }
2001 ExpressionBindingCollection expressionBindings;
2003 ExpressionBindingCollection IExpressionsAccessor.Expressions {
2005 if (expressionBindings == null)
2006 expressionBindings = new ExpressionBindingCollection ();
2007 return expressionBindings;
2011 bool IExpressionsAccessor.HasExpressions {
2012 get { return (expressionBindings != null && expressionBindings.Count > 0); }
2015 public virtual void Focus ()
2017 Page.SetFocus (this);
2020 protected internal virtual void LoadControlState (object state)
2024 protected internal virtual object SaveControlState ()
2029 protected virtual void DataBind (bool raiseOnDataBinding)
2031 bool foundDataItem = false;
2033 if ((stateMask & IS_NAMING_CONTAINER) != 0 && Page != null) {
2034 object o = DataBinder.GetDataItem (this, out foundDataItem);
2036 Page.PushDataItemContext (o);
2040 if (raiseOnDataBinding)
2041 OnDataBinding (EventArgs.Empty);
2042 DataBindChildren ();
2045 Page.PopDataItemContext ();
2049 protected virtual IDictionary GetDesignModeState ()
2051 throw new NotImplementedException ();
2054 protected virtual void SetDesignModeState (IDictionary data)
2056 throw new NotImplementedException ();
2059 internal bool IsInited {
2060 get { return (stateMask & INITED) != 0; }
2063 internal bool IsLoaded {
2064 get { return (stateMask & LOADED) != 0; }
2067 internal bool IsPrerendered {
2068 get { return (stateMask & PRERENDERED) != 0; }
2071 bool CheckForValidationSupport ()
2073 return GetType ().GetCustomAttributes (typeof (SupportsEventValidationAttribute), false).Length > 0;
2077 // Apparently this is where .NET routes validation from all the controls which
2080 // http://odetocode.com/Blogs/scott/archive/2006/03/20/3145.aspx
2081 // Sample in here contains ValidateEvent in the stack trace
2083 // http://odetocode.com/blogs/scott/archive/2006/03/21/3153.aspx
2085 // http://www.alexthissen.nl/blogs/main/archive/2005/12/13/event-validation-of-controls-in-asp-net-2-0.aspx
2087 // It also seems that it's the control's responsibility to call this method or
2088 // validation won't take place. Also, the SupportsEventValidation attribute must be
2089 // present on the control for validation to take place.
2091 internal void ValidateEvent (String uniqueId, String argument)
2095 if (page != null && CheckForValidationSupport ())
2096 page.ClientScript.ValidateEvent (uniqueId, argument);
2099 void IParserAccessor.AddParsedSubObject (object obj)
2101 this.AddParsedSubObject (obj);
2104 DataBindingCollection IDataBindingsAccessor.DataBindings {
2106 if (dataBindings == null) {
2107 dataBindings = new DataBindingCollection ();
2109 return dataBindings;
2113 bool IDataBindingsAccessor.HasDataBindings {
2115 if (dataBindings != null && dataBindings.Count > 0) {
2122 [ThemeableAttribute(false)]
2123 [DefaultValue ("0")]
2124 public virtual ViewStateMode ViewStateMode {
2125 get { return viewStateMode; }
2127 if (value < ViewStateMode.Inherit || value > ViewStateMode.Disabled)
2128 throw new ArgumentOutOfRangeException ("An attempt was made to set this property to a value that is not in the ViewStateMode enumeration.");
2130 viewStateMode = value;
2134 public string GetRouteUrl (object routeParameters)
2136 return GetRouteUrl (null, new RouteValueDictionary (routeParameters));
2139 public string GetRouteUrl (RouteValueDictionary routeParameters)
2141 return GetRouteUrl (null, routeParameters);
2144 public string GetRouteUrl (string routeName, object routeParameters)
2146 return GetRouteUrl (routeName, new RouteValueDictionary (routeParameters));
2149 public string GetRouteUrl (string routeName, RouteValueDictionary routeParameters)
2151 HttpContext ctx = Context ?? HttpContext.Current;
2152 HttpRequest req = ctx != null ? ctx.Request : null;
2157 VirtualPathData vpd = RouteTable.Routes.GetVirtualPath (req.RequestContext, routeName, routeParameters);
2161 return vpd.VirtualPath;
2164 public string GetUniqueIDRelativeTo (Control control)
2166 if (control == null)
2167 throw new ArgumentNullException ("control");
2169 Control parent = this;
2170 Control namingContainer = control.NamingContainer;
2172 if (namingContainer != null)
2173 while (parent != null && parent != namingContainer)
2174 parent = parent.Parent;
2176 if (parent != namingContainer)
2177 throw new InvalidOperationException (
2178 String.Format ("This control is not a descendant of the NamingContainer of '{0}'", control.UniqueID)
2181 int idx = control.UniqueID.LastIndexOf (IdSeparator);
2185 return UniqueID.Substring (idx + 1);