2 // System.Web.UI.UserControl.cs
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) 2002 Ximian, Inc (http://www.ximian.com)
9 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.ComponentModel;
32 using System.ComponentModel.Design;
33 using System.ComponentModel.Design.Serialization;
34 using System.Security.Permissions;
35 using System.Web.Caching;
36 using System.Web.SessionState;
38 namespace System.Web.UI
41 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
44 [ControlBuilder (typeof (UserControlControlBuilder))]
45 [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
47 [Designer ("System.Web.UI.Design.UserControlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
48 [ParseChildren (true)]
49 [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
50 public class UserControl : TemplateControl, IAttributeAccessor, IUserControlDesignerAccessor, INamingContainer, IFilterResolutionService, INonBindingContainer
52 ControlCachePolicy cachePolicy;
54 AttributeCollection attributes;
61 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
63 public HttpApplicationState Application
73 void EnsureAttributes ()
75 if (attributes == null) {
76 attrBag = new StateBag (true);
77 if (IsTrackingViewState)
78 attrBag.TrackViewState ();
79 attributes = new AttributeCollection (attrBag);
83 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
85 public AttributeCollection Attributes
93 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
105 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
107 public ControlCachePolicy CachePolicy
110 BasePartialCachingControl bpcc = Parent as BasePartialCachingControl;
113 return bpcc.CachePolicy;
115 if (cachePolicy == null)
116 cachePolicy = new ControlCachePolicy ();
121 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
123 public bool IsPostBack
133 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
135 public HttpRequest Request
145 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
147 public HttpResponse Response
157 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
159 public HttpServerUtility Server
169 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
171 public HttpSessionState Session
181 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
183 public TraceContext Trace
193 [EditorBrowsable (EditorBrowsableState.Never)]
194 public void DesignerInitialize ()
196 InitRecursive (null);
199 [EditorBrowsable (EditorBrowsableState.Never)]
200 public void InitializeAsUserControl (Page page)
205 InitializeAsUserControlInternal ();
208 internal void InitializeAsUserControlInternal ()
213 WireupAutomaticEvents ();
214 FrameworkInitialize ();
217 public string MapPath (string virtualPath)
219 return Request.MapPath (virtualPath, TemplateSourceDirectory, true);
222 protected override void LoadViewState (object savedState)
224 if (savedState != null) {
225 Pair p = (Pair) savedState;
226 base.LoadViewState (p.First);
227 if (p.Second != null) {
229 attrBag.LoadViewState (p.Second);
235 protected internal override void OnInit (EventArgs e)
237 InitializeAsUserControl (Page);
242 protected override object SaveViewState ()
244 object baseState = base.SaveViewState();
245 object attrState = null;
246 if (attributes != null)
247 attrState = attrBag.SaveViewState ();
248 if (baseState == null && attrState == null)
250 return new Pair (baseState, attrState);
253 string IAttributeAccessor.GetAttribute (string name)
255 if (attributes == null)
257 return attributes [name];
260 void IAttributeAccessor.SetAttribute (string name, string value)
263 Attributes [name] = value;
266 string IUserControlDesignerAccessor.InnerText
269 string innerText = ((string) ViewState["!DesignTimeInnerText"]);
270 if (innerText == null)
274 set { ViewState["!DesignTimeInnerText"] = value; }
277 string IUserControlDesignerAccessor.TagName
280 string innerTag = ((string) ViewState["!DesignTimeTagName"]);
281 if (innerTag == null)
285 set { ViewState["!DesignTimeTagName"] = value; }
288 [MonoTODO ("Not implemented")]
289 int IFilterResolutionService.CompareFilters (string filter1, string filter2)
291 throw new NotImplementedException ();
294 [MonoTODO ("Not implemented")]
295 bool IFilterResolutionService.EvaluateFilter (string filterName)
297 throw new NotImplementedException ();