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 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)]
50 [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
52 [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
54 public class UserControl : TemplateControl, IAttributeAccessor, IUserControlDesignerAccessor
56 , INamingContainer, IFilterResolutionService, INonBindingContainer
60 ControlCachePolicy cachePolicy;
63 AttributeCollection attributes;
70 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
72 public HttpApplicationState Application
82 void EnsureAttributes ()
84 if (attributes == null) {
85 attrBag = new StateBag (true);
86 if (IsTrackingViewState)
87 attrBag.TrackViewState ();
88 attributes = new AttributeCollection (attrBag);
92 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
94 public AttributeCollection Attributes
102 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
115 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
117 public ControlCachePolicy CachePolicy
120 BasePartialCachingControl bpcc = Parent as BasePartialCachingControl;
123 return bpcc.CachePolicy;
125 if (cachePolicy == null)
126 cachePolicy = new ControlCachePolicy ();
132 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
134 public bool IsPostBack
144 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
146 public HttpRequest Request
156 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
158 public HttpResponse Response
168 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
170 public HttpServerUtility Server
180 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
182 public HttpSessionState Session
192 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
194 public TraceContext Trace
204 [EditorBrowsable (EditorBrowsableState.Never)]
205 public void DesignerInitialize ()
207 InitRecursive (null);
210 [EditorBrowsable (EditorBrowsableState.Never)]
211 public void InitializeAsUserControl (Page page)
216 InitializeAsUserControlInternal ();
219 internal void InitializeAsUserControlInternal ()
224 WireupAutomaticEvents ();
225 FrameworkInitialize ();
228 public string MapPath (string virtualPath)
230 return Request.MapPath (virtualPath, TemplateSourceDirectory, true);
233 protected override void LoadViewState (object savedState)
235 if (savedState != null) {
236 Pair p = (Pair) savedState;
237 base.LoadViewState (p.First);
238 if (p.Second != null) {
240 attrBag.LoadViewState (p.Second);
251 override void OnInit (EventArgs e)
253 InitializeAsUserControl (Page);
258 protected override object SaveViewState ()
260 object baseState = base.SaveViewState();
261 object attrState = null;
262 if (attributes != null)
263 attrState = attrBag.SaveViewState ();
264 if (baseState == null && attrState == null)
266 return new Pair (baseState, attrState);
269 string IAttributeAccessor.GetAttribute (string name)
271 if (attributes == null)
273 return attributes [name];
276 void IAttributeAccessor.SetAttribute (string name, string value)
279 Attributes [name] = value;
282 string IUserControlDesignerAccessor.InnerText
285 string innerText = ((string) ViewState["!DesignTimeInnerText"]);
286 if (innerText == null)
290 set { ViewState["!DesignTimeInnerText"] = value; }
293 string IUserControlDesignerAccessor.TagName
296 string innerTag = ((string) ViewState["!DesignTimeTagName"]);
297 if (innerTag == null)
301 set { ViewState["!DesignTimeTagName"] = value; }
304 [MonoTODO ("Not implemented")]
305 int IFilterResolutionService.CompareFilters (string filter1, string filter2)
307 throw new NotImplementedException ();
310 [MonoTODO ("Not implemented")]
311 bool IFilterResolutionService.EvaluateFilter (string filterName)
313 throw new NotImplementedException ();