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))]
49 [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
50 [ParseChildren (true, "", ChildControlType = typeof (Control))]
52 [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
53 [ParseChildren (true)]
55 public class UserControl : TemplateControl, IAttributeAccessor, IUserControlDesignerAccessor
57 , INamingContainer, IFilterResolutionService
60 private bool initialized;
61 private AttributeCollection attributes;
62 private StateBag attrBag;
68 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
70 public HttpApplicationState Application
80 private void EnsureAttributes ()
82 if (attributes == null) {
83 attrBag = new StateBag (true);
84 if (IsTrackingViewState)
85 attrBag.TrackViewState ();
86 attributes = new AttributeCollection (attrBag);
90 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
92 public AttributeCollection Attributes
100 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
113 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
115 public ControlCachePolicy CachePolicy
118 throw new NotImplementedException ();
123 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
125 public bool IsPostBack
135 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
137 public HttpRequest Request
147 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
149 public HttpResponse Response
159 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
161 public HttpServerUtility Server
171 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
173 public HttpSessionState Session
183 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
185 public TraceContext Trace
195 [EditorBrowsable (EditorBrowsableState.Never)]
196 public void DesignerInitialize ()
198 InitRecursive (null);
201 [EditorBrowsable (EditorBrowsableState.Never)]
202 public void InitializeAsUserControl (Page page)
208 WireupAutomaticEvents ();
209 FrameworkInitialize ();
212 public string MapPath (string virtualPath)
214 return Request.MapPath (virtualPath, TemplateSourceDirectory, true);
217 protected override void LoadViewState (object savedState)
219 if (savedState != null) {
220 Pair p = (Pair) savedState;
221 base.LoadViewState (p.First);
222 if (p.Second != null) {
224 attrBag.LoadViewState (p.Second);
235 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; }
289 int IFilterResolutionService.CompareFilters (string filter1, string filter2)
291 throw new NotImplementedException ();
295 bool IFilterResolutionService.EvaluateFilter (string filterName)
297 throw new NotImplementedException ();