Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / WebControls / Label.cs / 1305376 / Label.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.Util; ////// public class LabelControlBuilder : ControlBuilder { ///Interacts with the parser to build a ///control. /// /// public override bool AllowWhitespaceLiterals() { return false; } } ///Specifies whether white space literals are allowed. ////// [ ControlBuilderAttribute(typeof(LabelControlBuilder)), ControlValueProperty("Text"), DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + AssemblyRef.SystemDesign), DefaultProperty("Text"), ParseChildren(false), Designer("System.Web.UI.Design.WebControls.LabelDesigner, " + AssemblyRef.SystemDesign), ToolboxData("<{0}:Label runat=\"server\" Text=\"Label\">{0}:Label>") ] public class Label : WebControl, ITextControl { private bool _textSetByAddParsedSubObject = false; ///Constructs a label for displaying text programmatcially on a /// page. ////// public Label() { } ///Initializes a new instance of the ///class and renders /// it as a SPAN tag. /// internal Label(HtmlTextWriterTag tag) : base(tag) { } ////// [ DefaultValue(""), IDReferenceProperty(), TypeConverter(typeof(AssociatedControlConverter)), WebCategory("Accessibility"), WebSysDescription(SR.Label_AssociatedControlID), Themeable(false) ] public virtual string AssociatedControlID { get { string s = (string)ViewState["AssociatedControlID"]; return (s == null) ? String.Empty : s; } set { ViewState["AssociatedControlID"] = value; } } internal bool AssociatedControlInControlTree { get { object o = ViewState["AssociatedControlNotInControlTree"]; return (o == null ? true : (bool)o); } set { ViewState["AssociatedControlNotInControlTree"] = value; } } public override bool SupportsDisabledAttribute { get { return RenderingCompatibility < VersionUtil.Framework40; } } internal override bool RequiresLegacyRendering { get { return true; } } protected override HtmlTextWriterTag TagKey { get { if (AssociatedControlID.Length != 0) { return HtmlTextWriterTag.Label; } return base.TagKey; } } ///[To be supplied.] ////// [ Localizable(true), Bindable(true), WebCategory("Appearance"), DefaultValue(""), WebSysDescription(SR.Label_Text), PersistenceMode(PersistenceMode.InnerDefaultProperty) ] public virtual string Text { get { object o = ViewState["Text"]; return((o == null) ? String.Empty : (string)o); } set { if (HasControls()) { Controls.Clear(); } ViewState["Text"] = value; } } protected override void AddAttributesToRender(HtmlTextWriter writer) { string associatedControlID = AssociatedControlID; if (associatedControlID.Length != 0) { if (AssociatedControlInControlTree) { Control wc = FindControl(associatedControlID); if (wc == null) { // Don't throw in the designer. if (!DesignMode) throw new HttpException(SR.GetString(SR.LabelForNotFound, associatedControlID, ID)); } else { writer.AddAttribute(HtmlTextWriterAttribute.For, wc.ClientID); } } else { writer.AddAttribute(HtmlTextWriterAttribute.For, associatedControlID); } } base.AddAttributesToRender(writer); } ///Gets or sets the text content of the ////// control. /// /// protected override void AddParsedSubObject(object obj) { if (HasControls()) { base.AddParsedSubObject(obj); } else { if (obj is LiteralControl) { if (_textSetByAddParsedSubObject) { Text += ((LiteralControl)obj).Text; } else { Text = ((LiteralControl)obj).Text; } _textSetByAddParsedSubObject = true; } else { string currentText = Text; if (currentText.Length != 0) { Text = String.Empty; base.AddParsedSubObject(new LiteralControl(currentText)); } base.AddParsedSubObject(obj); } } } ////// /// protected override void LoadViewState(object savedState) { if (savedState != null) { base.LoadViewState(savedState); string s = (string)ViewState["Text"]; // Dev10 703061 If Text is set, we want to clear out any child controls, but not dirty viewstate if (s != null && HasControls()) { Controls.Clear(); } } } ///Load previously saved state. /// Overridden to synchronize Text property with LiteralContent. ////// /// protected internal override void RenderContents(HtmlTextWriter writer) { if (HasRenderingData()) { base.RenderContents(writer); } else { writer.Write(Text); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //Renders the contents of the ///into the specified writer. // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.Util; ////// public class LabelControlBuilder : ControlBuilder { ///Interacts with the parser to build a ///control. /// /// public override bool AllowWhitespaceLiterals() { return false; } } ///Specifies whether white space literals are allowed. ////// [ ControlBuilderAttribute(typeof(LabelControlBuilder)), ControlValueProperty("Text"), DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + AssemblyRef.SystemDesign), DefaultProperty("Text"), ParseChildren(false), Designer("System.Web.UI.Design.WebControls.LabelDesigner, " + AssemblyRef.SystemDesign), ToolboxData("<{0}:Label runat=\"server\" Text=\"Label\">{0}:Label>") ] public class Label : WebControl, ITextControl { private bool _textSetByAddParsedSubObject = false; ///Constructs a label for displaying text programmatcially on a /// page. ////// public Label() { } ///Initializes a new instance of the ///class and renders /// it as a SPAN tag. /// internal Label(HtmlTextWriterTag tag) : base(tag) { } ////// [ DefaultValue(""), IDReferenceProperty(), TypeConverter(typeof(AssociatedControlConverter)), WebCategory("Accessibility"), WebSysDescription(SR.Label_AssociatedControlID), Themeable(false) ] public virtual string AssociatedControlID { get { string s = (string)ViewState["AssociatedControlID"]; return (s == null) ? String.Empty : s; } set { ViewState["AssociatedControlID"] = value; } } internal bool AssociatedControlInControlTree { get { object o = ViewState["AssociatedControlNotInControlTree"]; return (o == null ? true : (bool)o); } set { ViewState["AssociatedControlNotInControlTree"] = value; } } public override bool SupportsDisabledAttribute { get { return RenderingCompatibility < VersionUtil.Framework40; } } internal override bool RequiresLegacyRendering { get { return true; } } protected override HtmlTextWriterTag TagKey { get { if (AssociatedControlID.Length != 0) { return HtmlTextWriterTag.Label; } return base.TagKey; } } ///[To be supplied.] ////// [ Localizable(true), Bindable(true), WebCategory("Appearance"), DefaultValue(""), WebSysDescription(SR.Label_Text), PersistenceMode(PersistenceMode.InnerDefaultProperty) ] public virtual string Text { get { object o = ViewState["Text"]; return((o == null) ? String.Empty : (string)o); } set { if (HasControls()) { Controls.Clear(); } ViewState["Text"] = value; } } protected override void AddAttributesToRender(HtmlTextWriter writer) { string associatedControlID = AssociatedControlID; if (associatedControlID.Length != 0) { if (AssociatedControlInControlTree) { Control wc = FindControl(associatedControlID); if (wc == null) { // Don't throw in the designer. if (!DesignMode) throw new HttpException(SR.GetString(SR.LabelForNotFound, associatedControlID, ID)); } else { writer.AddAttribute(HtmlTextWriterAttribute.For, wc.ClientID); } } else { writer.AddAttribute(HtmlTextWriterAttribute.For, associatedControlID); } } base.AddAttributesToRender(writer); } ///Gets or sets the text content of the ////// control. /// /// protected override void AddParsedSubObject(object obj) { if (HasControls()) { base.AddParsedSubObject(obj); } else { if (obj is LiteralControl) { if (_textSetByAddParsedSubObject) { Text += ((LiteralControl)obj).Text; } else { Text = ((LiteralControl)obj).Text; } _textSetByAddParsedSubObject = true; } else { string currentText = Text; if (currentText.Length != 0) { Text = String.Empty; base.AddParsedSubObject(new LiteralControl(currentText)); } base.AddParsedSubObject(obj); } } } ////// /// protected override void LoadViewState(object savedState) { if (savedState != null) { base.LoadViewState(savedState); string s = (string)ViewState["Text"]; // Dev10 703061 If Text is set, we want to clear out any child controls, but not dirty viewstate if (s != null && HasControls()) { Controls.Clear(); } } } ///Load previously saved state. /// Overridden to synchronize Text property with LiteralContent. ////// /// protected internal override void RenderContents(HtmlTextWriter writer) { if (HasRenderingData()) { base.RenderContents(writer); } else { writer.Write(Text); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.Renders the contents of the ///into the specified writer.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ThreadStaticAttribute.cs
- FixedSOMPageConstructor.cs
- DocumentGridContextMenu.cs
- HashCodeCombiner.cs
- RightsManagementEncryptedStream.cs
- DetailsViewRowCollection.cs
- DataServiceHost.cs
- LowerCaseStringConverter.cs
- PersonalizationState.cs
- _ServiceNameStore.cs
- InlinedAggregationOperator.cs
- LayoutManager.cs
- LocatorManager.cs
- PropertyValueUIItem.cs
- DependentList.cs
- ResXFileRef.cs
- OutputCacheModule.cs
- OutputChannelBinder.cs
- SpecialFolderEnumConverter.cs
- LinqDataSourceSelectEventArgs.cs
- HttpCookieCollection.cs
- AddingNewEventArgs.cs
- RequestContextBase.cs
- DirectoryRootQuery.cs
- IncrementalReadDecoders.cs
- ProcessModelInfo.cs
- DataSourceControl.cs
- smtppermission.cs
- XsdDuration.cs
- WebPartConnectionsEventArgs.cs
- InfoCardSchemas.cs
- ReliableSessionBindingElementImporter.cs
- Helper.cs
- ClaimSet.cs
- ReadOnlyPropertyMetadata.cs
- ListChangedEventArgs.cs
- Geometry3D.cs
- MetadataItemEmitter.cs
- CoordinationService.cs
- SessionEndedEventArgs.cs
- connectionpool.cs
- ConnectionConsumerAttribute.cs
- ConfigurationLocationCollection.cs
- TypeDelegator.cs
- SystemFonts.cs
- SafeLocalMemHandle.cs
- SystemColors.cs
- Soap.cs
- MLangCodePageEncoding.cs
- DataBinding.cs
- input.cs
- DockPatternIdentifiers.cs
- ParallelLoopState.cs
- ForceCopyBuildProvider.cs
- WeakHashtable.cs
- ReadOnlyHierarchicalDataSource.cs
- VectorCollection.cs
- XmlSchemaDatatype.cs
- LoadWorkflowAsyncResult.cs
- nulltextnavigator.cs
- UnknownBitmapEncoder.cs
- StagingAreaInputItem.cs
- WindowsAuthenticationEventArgs.cs
- ObjectTag.cs
- SqlDependencyListener.cs
- StreamHelper.cs
- Registry.cs
- Size3DValueSerializer.cs
- SelectorAutomationPeer.cs
- PKCS1MaskGenerationMethod.cs
- Identity.cs
- XmlILIndex.cs
- SiteMapProvider.cs
- KnownTypeHelper.cs
- RadioButtonBaseAdapter.cs
- SmiContextFactory.cs
- x509utils.cs
- Triplet.cs
- WebPartConnectionsConnectVerb.cs
- PathNode.cs
- DefaultShape.cs
- CommonObjectSecurity.cs
- TcpConnectionPoolSettingsElement.cs
- HierarchicalDataSourceControl.cs
- ScriptControlDescriptor.cs
- DragStartedEventArgs.cs
- RootDesignerSerializerAttribute.cs
- RightsManagementEncryptionTransform.cs
- ServiceXNameTypeConverter.cs
- XPathNavigatorKeyComparer.cs
- Drawing.cs
- SspiWrapper.cs
- ArrangedElement.cs
- WebPartConnectVerb.cs
- CapabilitiesState.cs
- CompositionDesigner.cs
- HttpVersion.cs
- SelectiveScrollingGrid.cs
- WaitHandle.cs
- SecurityKeyIdentifier.cs