Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / xsp / System / Web / UI / UserControl.cs / 1 / UserControl.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Page class definition * * Copyright (c) 1998 Microsoft Corporation */ namespace System.Web.UI { using System; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Web.SessionState; using System.Web.Caching; using System.Security.Permissions; using System.Web.Util; ////// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class UserControlControlBuilder : ControlBuilder { private string _innerText; ///The ControlBuilder associated with a UserControl. If you want a custom ControlBuilder for your /// derived UserControl, you should derive it from UserControlControlBuilder. /// ///public override object BuildObject() { object o = base.BuildObject(); if (InDesigner) { IUserControlDesignerAccessor designerAccessor = (IUserControlDesignerAccessor)o; designerAccessor.TagName = TagName; if (_innerText != null) { designerAccessor.InnerText = _innerText; } } return o; } /// public override bool NeedsTagInnerText() { // in design-mode, we need to hang on to the inner text return InDesigner; } /// public override void SetTagInnerText(string text) { Debug.Assert(InDesigner == true, "Should only be called in design-mode!"); _innerText = text; } } /// /// Default ControlBuilder used to parse user controls files. /// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class FileLevelUserControlBuilder: RootBuilder { } ////// [ ControlBuilder(typeof(UserControlControlBuilder)), DefaultEvent("Load"), Designer("System.Web.UI.Design.UserControlDesigner, " + AssemblyRef.SystemDesign, typeof(IDesigner)), Designer("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + AssemblyRef.MicrosoftVisualStudioWeb, typeof(IRootDesigner)), DesignerCategory("ASPXCodeBehind"), DesignerSerializer("Microsoft.VisualStudio.Web.WebForms.WebFormCodeDomSerializer, " + AssemblyRef.MicrosoftVisualStudioWeb, "System.ComponentModel.Design.Serialization.TypeCodeDomSerializer, " + AssemblyRef.SystemDesign), ParseChildren(true), ToolboxItem(false) ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class UserControl : TemplateControl, IAttributeAccessor, INonBindingContainer, IUserControlDesignerAccessor { private StateBag attributeStorage; private AttributeCollection attributes; private bool _fUserControlInitialized; ///This class is not marked as abstract, because the VS designer /// needs to instantiate it when opening .ascx files ////// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public AttributeCollection Attributes { get { if (attributes == null) { if (attributeStorage == null) { attributeStorage = new StateBag(true); if (IsTrackingViewState) { attributeStorage.TrackViewState(); } } attributes = new AttributeCollection(attributeStorage); } return attributes; } } // Delegate most things to the Page ///Gets the collection of attribute name/value pairs expressed on a UserControl but /// not supported by the control's strongly typed properties. ////// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpApplicationState Application { get { return Page.Application;} } /* * Trace context for output of useful information to page during development */ ///Gets the ///object provided by /// the HTTP Runtime. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public TraceContext Trace { get { return Page.Trace; } } ///Indicates the ///object for the current Web /// request. Tracing tracks and presents the execution details about a Web request. /// For trace data to be visible in a rendered page, you must turn tracing on for /// that page. This property is read-only. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpRequest Request { get { return Page.Request; } } ////// Gets the ///object provided by the HTTP Runtime, which /// allows developers to access data from incoming HTTP requests. /// /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpResponse Response { get { return Page.Response; } } ///Gets the ///object provided by the HTTP Runtime, which /// allows developers to send HTTP response data to a client browser. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpServerUtility Server { get { return Page.Server; } } /* * Cache intrinsic */ ///Gets the ASP-compatible ///object. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public Cache Cache { get { return Page.Cache; } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public ControlCachePolicy CachePolicy { get { // Check if we're inside a PartialCachingControl BasePartialCachingControl pcc = Parent as BasePartialCachingControl; // If so, return its CachePolicy if (pcc != null) return pcc.CachePolicy; // Otherwise, return a stub, which returns SupportsCaching==false and throws // on everything else. return ControlCachePolicy.GetCachePolicyStub(); } } ///Retrieves a ////// object in which to store the user control's data for /// subsequent requests. This property is read-only. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public bool IsPostBack { get { return Page.IsPostBack; } } ///Gets a value indicating whether the user control is being loaded in response to a /// client postback, or if it is being loaded and accessed for the first time. ////// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpSessionState Session { get { return Page.Session; } } /* * Performs intialization of the control required by the designer. */ ///Gets the ///object provided by the HTTP Runtime. /// [EditorBrowsable(EditorBrowsableState.Never)] public void DesignerInitialize() { InitRecursive(null); } ///Performs any initialization of the control that is required by RAD designers. ////// protected internal override void OnInit(EventArgs e) { // We want to avoid calling this when the user control is being used in the designer, // regardless of whether it is a top-level control (DesignMode == true), // or if its inside another control in design-mode (Page.Site.DesignMode == true) bool designTime = DesignMode; if (designTime == false) { if ((Page != null) && (Page.Site != null)) { designTime = Page.Site.DesignMode; } } if (designTime == false) { InitializeAsUserControlInternal(); } base.OnInit(e); } /* * Called on declarative controls to initialize them correctly */ ///[To be supplied.] ////// [EditorBrowsable(EditorBrowsableState.Never)] public void InitializeAsUserControl(Page page) { _page = page; InitializeAsUserControlInternal(); } internal void InitializeAsUserControlInternal() { // Make sure we only do this once if (_fUserControlInitialized) return; _fUserControlInitialized = true; // Hook up any automatic handler we may find (e.g. Page_Load) HookUpAutomaticHandlers(); // Initialize the object and instantiate all the controls defined in the ascx file FrameworkInitialize(); } protected override void LoadViewState(object savedState) { if (savedState != null) { Pair myState = (Pair)savedState; base.LoadViewState(myState.First); if (myState.Second != null) { if (attributeStorage == null) { attributeStorage = new StateBag(true); attributeStorage.TrackViewState(); } attributeStorage.LoadViewState(myState.Second); } } } protected override object SaveViewState() { Pair myState = null; object baseState = base.SaveViewState(); object attrState = null; if (attributeStorage != null) { attrState = attributeStorage.SaveViewState(); } if (baseState != null || attrState != null) { myState = new Pair(baseState, attrState); } return myState; } ///Initializes the ///object. Since there are some /// differences between pages and user controls, this method makes sure that the /// user control is initialized properly. /// /// Returns the attribute value of the UserControl having /// the specified attribute name. /// string IAttributeAccessor.GetAttribute(string name) { return ((attributeStorage != null) ? (string)attributeStorage[name] : null); } ////// /// void IAttributeAccessor.SetAttribute(string name, string value) { Attributes[name] = value; } /* * Map virtual path (absolute or relative) to physical path */ ///Sets an attribute of the UserControl with the specified /// name and value. ////// public string MapPath(string virtualPath) { return Request.MapPath(VirtualPath.CreateAllowNull(virtualPath), TemplateControlVirtualDirectory, true/*allowCrossAppMapping*/); } ///Assigns a virtual path, either absolute or relative, to a physical path. ///string IUserControlDesignerAccessor.TagName { get { string text = (string)ViewState["!DesignTimeTagName"]; if (text == null) { return String.Empty; } return text; } set { ViewState["!DesignTimeTagName"] = value; } } /// string IUserControlDesignerAccessor.InnerText { get { string text = (string)ViewState["!DesignTimeInnerText"]; if (text == null) { return String.Empty; } return text; } set { ViewState["!DesignTimeInnerText"] = value; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Page class definition * * Copyright (c) 1998 Microsoft Corporation */ namespace System.Web.UI { using System; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Web.SessionState; using System.Web.Caching; using System.Security.Permissions; using System.Web.Util; ////// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class UserControlControlBuilder : ControlBuilder { private string _innerText; ///The ControlBuilder associated with a UserControl. If you want a custom ControlBuilder for your /// derived UserControl, you should derive it from UserControlControlBuilder. /// ///public override object BuildObject() { object o = base.BuildObject(); if (InDesigner) { IUserControlDesignerAccessor designerAccessor = (IUserControlDesignerAccessor)o; designerAccessor.TagName = TagName; if (_innerText != null) { designerAccessor.InnerText = _innerText; } } return o; } /// public override bool NeedsTagInnerText() { // in design-mode, we need to hang on to the inner text return InDesigner; } /// public override void SetTagInnerText(string text) { Debug.Assert(InDesigner == true, "Should only be called in design-mode!"); _innerText = text; } } /// /// Default ControlBuilder used to parse user controls files. /// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class FileLevelUserControlBuilder: RootBuilder { } ////// [ ControlBuilder(typeof(UserControlControlBuilder)), DefaultEvent("Load"), Designer("System.Web.UI.Design.UserControlDesigner, " + AssemblyRef.SystemDesign, typeof(IDesigner)), Designer("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + AssemblyRef.MicrosoftVisualStudioWeb, typeof(IRootDesigner)), DesignerCategory("ASPXCodeBehind"), DesignerSerializer("Microsoft.VisualStudio.Web.WebForms.WebFormCodeDomSerializer, " + AssemblyRef.MicrosoftVisualStudioWeb, "System.ComponentModel.Design.Serialization.TypeCodeDomSerializer, " + AssemblyRef.SystemDesign), ParseChildren(true), ToolboxItem(false) ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class UserControl : TemplateControl, IAttributeAccessor, INonBindingContainer, IUserControlDesignerAccessor { private StateBag attributeStorage; private AttributeCollection attributes; private bool _fUserControlInitialized; ///This class is not marked as abstract, because the VS designer /// needs to instantiate it when opening .ascx files ////// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public AttributeCollection Attributes { get { if (attributes == null) { if (attributeStorage == null) { attributeStorage = new StateBag(true); if (IsTrackingViewState) { attributeStorage.TrackViewState(); } } attributes = new AttributeCollection(attributeStorage); } return attributes; } } // Delegate most things to the Page ///Gets the collection of attribute name/value pairs expressed on a UserControl but /// not supported by the control's strongly typed properties. ////// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpApplicationState Application { get { return Page.Application;} } /* * Trace context for output of useful information to page during development */ ///Gets the ///object provided by /// the HTTP Runtime. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public TraceContext Trace { get { return Page.Trace; } } ///Indicates the ///object for the current Web /// request. Tracing tracks and presents the execution details about a Web request. /// For trace data to be visible in a rendered page, you must turn tracing on for /// that page. This property is read-only. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpRequest Request { get { return Page.Request; } } ////// Gets the ///object provided by the HTTP Runtime, which /// allows developers to access data from incoming HTTP requests. /// /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpResponse Response { get { return Page.Response; } } ///Gets the ///object provided by the HTTP Runtime, which /// allows developers to send HTTP response data to a client browser. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpServerUtility Server { get { return Page.Server; } } /* * Cache intrinsic */ ///Gets the ASP-compatible ///object. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public Cache Cache { get { return Page.Cache; } } [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public ControlCachePolicy CachePolicy { get { // Check if we're inside a PartialCachingControl BasePartialCachingControl pcc = Parent as BasePartialCachingControl; // If so, return its CachePolicy if (pcc != null) return pcc.CachePolicy; // Otherwise, return a stub, which returns SupportsCaching==false and throws // on everything else. return ControlCachePolicy.GetCachePolicyStub(); } } ///Retrieves a ////// object in which to store the user control's data for /// subsequent requests. This property is read-only. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public bool IsPostBack { get { return Page.IsPostBack; } } ///Gets a value indicating whether the user control is being loaded in response to a /// client postback, or if it is being loaded and accessed for the first time. ////// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public HttpSessionState Session { get { return Page.Session; } } /* * Performs intialization of the control required by the designer. */ ///Gets the ///object provided by the HTTP Runtime. /// [EditorBrowsable(EditorBrowsableState.Never)] public void DesignerInitialize() { InitRecursive(null); } ///Performs any initialization of the control that is required by RAD designers. ////// protected internal override void OnInit(EventArgs e) { // We want to avoid calling this when the user control is being used in the designer, // regardless of whether it is a top-level control (DesignMode == true), // or if its inside another control in design-mode (Page.Site.DesignMode == true) bool designTime = DesignMode; if (designTime == false) { if ((Page != null) && (Page.Site != null)) { designTime = Page.Site.DesignMode; } } if (designTime == false) { InitializeAsUserControlInternal(); } base.OnInit(e); } /* * Called on declarative controls to initialize them correctly */ ///[To be supplied.] ////// [EditorBrowsable(EditorBrowsableState.Never)] public void InitializeAsUserControl(Page page) { _page = page; InitializeAsUserControlInternal(); } internal void InitializeAsUserControlInternal() { // Make sure we only do this once if (_fUserControlInitialized) return; _fUserControlInitialized = true; // Hook up any automatic handler we may find (e.g. Page_Load) HookUpAutomaticHandlers(); // Initialize the object and instantiate all the controls defined in the ascx file FrameworkInitialize(); } protected override void LoadViewState(object savedState) { if (savedState != null) { Pair myState = (Pair)savedState; base.LoadViewState(myState.First); if (myState.Second != null) { if (attributeStorage == null) { attributeStorage = new StateBag(true); attributeStorage.TrackViewState(); } attributeStorage.LoadViewState(myState.Second); } } } protected override object SaveViewState() { Pair myState = null; object baseState = base.SaveViewState(); object attrState = null; if (attributeStorage != null) { attrState = attributeStorage.SaveViewState(); } if (baseState != null || attrState != null) { myState = new Pair(baseState, attrState); } return myState; } ///Initializes the ///object. Since there are some /// differences between pages and user controls, this method makes sure that the /// user control is initialized properly. /// /// Returns the attribute value of the UserControl having /// the specified attribute name. /// string IAttributeAccessor.GetAttribute(string name) { return ((attributeStorage != null) ? (string)attributeStorage[name] : null); } ////// /// void IAttributeAccessor.SetAttribute(string name, string value) { Attributes[name] = value; } /* * Map virtual path (absolute or relative) to physical path */ ///Sets an attribute of the UserControl with the specified /// name and value. ////// public string MapPath(string virtualPath) { return Request.MapPath(VirtualPath.CreateAllowNull(virtualPath), TemplateControlVirtualDirectory, true/*allowCrossAppMapping*/); } ///Assigns a virtual path, either absolute or relative, to a physical path. ///string IUserControlDesignerAccessor.TagName { get { string text = (string)ViewState["!DesignTimeTagName"]; if (text == null) { return String.Empty; } return text; } set { ViewState["!DesignTimeTagName"] = value; } } /// string IUserControlDesignerAccessor.InnerText { get { string text = (string)ViewState["!DesignTimeInnerText"]; if (text == null) { return String.Empty; } return text; } set { ViewState["!DesignTimeInnerText"] = value; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DefinitionUpdate.cs
- TraceUtils.cs
- TdsParserSafeHandles.cs
- GridViewPageEventArgs.cs
- DbDataReader.cs
- NativeObjectSecurity.cs
- ServerValidateEventArgs.cs
- VariableQuery.cs
- NativeMethods.cs
- TreeNode.cs
- DesignerVerbCollection.cs
- StatusBar.cs
- RootBrowserWindow.cs
- LayoutEngine.cs
- IssuanceLicense.cs
- SafeFileHandle.cs
- BaseResourcesBuildProvider.cs
- XmlSerializationGeneratedCode.cs
- ObjectViewListener.cs
- Binding.cs
- TableParaClient.cs
- MemoryPressure.cs
- EntryPointNotFoundException.cs
- TypeBuilderInstantiation.cs
- GatewayDefinition.cs
- Brush.cs
- _AutoWebProxyScriptHelper.cs
- FixedSOMContainer.cs
- DataGridViewDesigner.cs
- WindowsUpDown.cs
- XhtmlBasicLiteralTextAdapter.cs
- NativeMethods.cs
- SecurityUtils.cs
- SessionPageStateSection.cs
- ComponentEditorPage.cs
- FileUtil.cs
- DirectoryInfo.cs
- SrgsRule.cs
- EntityDataSourceContextCreatingEventArgs.cs
- ScriptResourceMapping.cs
- FieldValue.cs
- InvalidComObjectException.cs
- DynamicPropertyHolder.cs
- FixedNode.cs
- FixedSOMImage.cs
- PersonalizationProviderHelper.cs
- VerticalAlignConverter.cs
- OdbcEnvironmentHandle.cs
- Type.cs
- MainMenu.cs
- ActivityCollectionMarkupSerializer.cs
- HttpHeaderCollection.cs
- Transform.cs
- StylusPointPropertyUnit.cs
- NodeInfo.cs
- CopyEncoder.cs
- Enum.cs
- FileDataSourceCache.cs
- ParallelForEach.cs
- ReplyChannelAcceptor.cs
- ImageCodecInfo.cs
- DataGridTableCollection.cs
- Positioning.cs
- InstalledFontCollection.cs
- GlyphCache.cs
- Transform.cs
- InternalDuplexChannelFactory.cs
- DataControlImageButton.cs
- CategoriesDocumentFormatter.cs
- _Win32.cs
- ExceptionRoutedEventArgs.cs
- InheritedPropertyChangedEventArgs.cs
- SpeechRecognizer.cs
- StdValidatorsAndConverters.cs
- _SslState.cs
- PropertyNames.cs
- RegisteredDisposeScript.cs
- AtomServiceDocumentSerializer.cs
- HandoffBehavior.cs
- RepeaterItem.cs
- WebPartsSection.cs
- SqlConnection.cs
- WmfPlaceableFileHeader.cs
- QuaternionAnimation.cs
- ExpressionVisitorHelpers.cs
- MetaTable.cs
- SoapMessage.cs
- Processor.cs
- SchemaImporterExtension.cs
- SecurityHelper.cs
- BitmapSource.cs
- UnitySerializationHolder.cs
- Attachment.cs
- SQLInt32.cs
- TextTreeTextNode.cs
- OleDbRowUpdatingEvent.cs
- SqlDependencyListener.cs
- DetailsViewInsertedEventArgs.cs
- AsmxEndpointPickerExtension.cs
- OracleException.cs