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
59 private bool initialized;
60 private AttributeCollection attributes;
61 private StateBag attrBag;
67 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
69 public HttpApplicationState Application
79 private void EnsureAttributes ()
81 if (attributes == null) {
82 attrBag = new StateBag (true);
83 if (IsTrackingViewState)
84 attrBag.TrackViewState ();
85 attributes = new AttributeCollection (attrBag);
89 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
91 public AttributeCollection Attributes
99 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
112 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
114 public ControlCachePolicy CachePolicy
117 throw new NotImplementedException ();
122 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
124 public bool IsPostBack
134 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
136 public HttpRequest Request
146 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
148 public HttpResponse Response
158 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
160 public HttpServerUtility Server
170 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
172 public HttpSessionState Session
182 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
184 public TraceContext Trace
194 [EditorBrowsable (EditorBrowsableState.Never)]
195 public void DesignerInitialize ()
197 InitRecursive (null);
200 [EditorBrowsable (EditorBrowsableState.Never)]
201 public void InitializeAsUserControl (Page page)
206 InitializeAsUserControlInternal ();
209 internal void InitializeAsUserControlInternal ()
214 WireupAutomaticEvents ();
215 FrameworkInitialize ();
218 public string MapPath (string virtualPath)
220 return Request.MapPath (virtualPath, TemplateSourceDirectory, true);
223 protected override void LoadViewState (object savedState)
225 if (savedState != null) {
226 Pair p = (Pair) savedState;
227 base.LoadViewState (p.First);
228 if (p.Second != null) {
230 attrBag.LoadViewState (p.Second);
241 override void OnInit (EventArgs e)
243 InitializeAsUserControl (Page);
248 protected override object SaveViewState ()
250 object baseState = base.SaveViewState();
251 object attrState = null;
252 if (attributes != null)
253 attrState = attrBag.SaveViewState ();
254 if (baseState == null && attrState == null)
256 return new Pair (baseState, attrState);
259 string IAttributeAccessor.GetAttribute (string name)
261 if (attributes == null)
263 return attributes [name];
266 void IAttributeAccessor.SetAttribute (string name, string value)
269 Attributes [name] = value;
272 string IUserControlDesignerAccessor.InnerText
275 string innerText = ((string) ViewState["!DesignTimeInnerText"]);
276 if (innerText == null)
280 set { ViewState["!DesignTimeInnerText"] = value; }
283 string IUserControlDesignerAccessor.TagName
286 string innerTag = ((string) ViewState["!DesignTimeTagName"]);
287 if (innerTag == null)
291 set { ViewState["!DesignTimeTagName"] = value; }
294 [MonoTODO ("Not implemented")]
295 int IFilterResolutionService.CompareFilters (string filter1, string filter2)
297 throw new NotImplementedException ();
300 [MonoTODO ("Not implemented")]
301 bool IFilterResolutionService.EvaluateFilter (string filterName)
303 throw new NotImplementedException ();