Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / UI / WebControls / listitem.cs / 1 / listitem.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Globalization; using AttributeCollection = System.Web.UI.AttributeCollection; using System.Security.Permissions; using System.Web.Util; ////// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class ListItemControlBuilder : ControlBuilder { public override bool AllowWhitespaceLiterals() { return false; } public override bool HtmlDecodeLiterals() { // ListItem text gets rendered as an encoded attribute value. // At parse time text specified as an attribute gets decoded, and so text specified as a // literal needs to go through the same process. return true; } } ///Interacts with the parser to build a ///control. /// [ ControlBuilderAttribute(typeof(ListItemControlBuilder)), TypeConverterAttribute(typeof(ExpandableObjectConverter)), ParseChildren(true, "Text"), ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class ListItem : IStateManager, IParserAccessor, IAttributeAccessor { private bool selected; private bool marked; private bool textisdirty; private bool valueisdirty; private bool enabled; private bool enabledisdirty; private string text; private string value; private AttributeCollection _attributes; ///Constructs a list item control and defines /// its properties. This class cannot be inherited. ////// public ListItem() : this(null, null) { } ///Initializes a new instance of the ///class. /// public ListItem(string text) : this(text, null) { } ///Initializes a new instance of the ///class with the specified text data. /// public ListItem(string text, string value) : this(text, value, true) { } ///Initializes a new instance of the ///class with the specified text data. /// public ListItem(string text, string value, bool enabled) { this.text = text; this.value = value; this.enabled = enabled; } ///Initializes a new instance of the ///class with the /// specified text and value data. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public AttributeCollection Attributes { get { if (_attributes == null) _attributes = new AttributeCollection(new StateBag(true)); return _attributes; } } ///Gets the collection of attribute name/value pairs expressed on the list item /// control but not supported by the control's strongly typed properties. ////// Internal property used to manage dirty state of ListItem. /// internal bool Dirty { get { return (textisdirty || valueisdirty || enabledisdirty); } set { textisdirty = value; valueisdirty = value; enabledisdirty = value; } } [ DefaultValue(true) ] public bool Enabled { get { return enabled; } set { enabled = value; if (((IStateManager)this).IsTrackingViewState) enabledisdirty = true; } } internal bool HasAttributes { get { return _attributes != null && _attributes.Count > 0; } } ////// [ DefaultValue(false), TypeConverter(typeof(MinimizableAttributeTypeConverter)) ] public bool Selected { get { return selected; } set { selected = value; } } ///Specifies a value indicating whether the /// item is selected. ////// [ Localizable(true), DefaultValue(""), PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty) ] public string Text { get { if (text != null) return text; if (value != null) return value; return String.Empty; } set { text = value; if (((IStateManager)this).IsTrackingViewState) textisdirty = true; } } ///Gets or sets the display text of the list /// item control. ////// [ Localizable(true), DefaultValue("") ] public string Value { get { if (value != null) return value; if (text != null) return text; return String.Empty; } set { this.value = value; if (((IStateManager)this).IsTrackingViewState) valueisdirty =true; } } ///Gets or sets the value content of the list item control. ///public override int GetHashCode() { return HashCodeCombiner.CombineHashCodes(Value.GetHashCode(), Text.GetHashCode()); } /// /// /// public override bool Equals(object o) { ListItem other = o as ListItem; if (other != null) { return Value.Equals(other.Value) && Text.Equals(other.Text); } return false; } ////// public static ListItem FromString(string s) { return new ListItem(s); } ///Creates a ///from the specified string. /// /// public override string ToString() { return this.Text; } ////// /// Return true if tracking state changes. /// Method of private interface, IStateManager. /// bool IStateManager.IsTrackingViewState { get { return marked; } } ///void IStateManager.LoadViewState(object state) { LoadViewState(state); } internal void LoadViewState(object state) { if (state != null) { if (state is Triplet) { Triplet t = (Triplet) state; if (t.First != null) { Text = (string) t.First; } if (t.Second != null) { Value = (string) t.Second; } if (t.Third != null) { try { Enabled = (bool) t.Third; } catch { } } } else if (state is Pair) { Pair p = (Pair) state; if (p.First != null) Text = (string) p.First; Value = (string) p.Second; } else Text = (string) state; } } /// void IStateManager.TrackViewState() { TrackViewState(); } internal void TrackViewState() { marked = true; } internal void RenderAttributes(HtmlTextWriter writer) { if (_attributes != null) { _attributes.AddAttributes(writer); } } /// object IStateManager.SaveViewState() { return SaveViewState(); } internal object SaveViewState() { string text = null; string value = null; if(textisdirty) { text = Text; } if(valueisdirty) { value = Value; } if(enabledisdirty) { return new Triplet(text, value, Enabled); } else if(valueisdirty) { return new Pair(text, value); } else if(textisdirty) { return text; } return null; } /// /// /// Returns the attribute value of the list item control /// having the specified attribute name. /// string IAttributeAccessor.GetAttribute(string name) { return Attributes[name]; } ////// /// void IAttributeAccessor.SetAttribute(string name, string value) { Attributes[name] = value; } ///Sets an attribute of the list /// item control with the specified name and value. ////// /// void IParserAccessor.AddParsedSubObject(object obj) { if (obj is LiteralControl) { Text = ((LiteralControl)obj).Text; } else { if (obj is DataBoundLiteralControl) { throw new HttpException(SR.GetString(SR.Control_Cannot_Databind, "ListItem")); } else { throw new HttpException(SR.GetString(SR.Cannot_Have_Children_Of_Type, "ListItem", obj.GetType().Name.ToString(CultureInfo.InvariantCulture))); } } } ///Allows the ////// property to be persisted as inner content. /// Do not change the signature or remove this method. It is called via reflection /// to support correct serialization behavior for Text and Value which are /// implemented as dependent properties. /// private void ResetText() { Text = null; } ////// Do not change the signature or remove this method. It is called via reflection /// to support correct serialization behavior for Text and Value which are /// implemented as dependent properties. /// private void ResetValue() { Value = null; } ////// Do not change the signature or remove this method. It is called via reflection /// to support correct serialization behavior for Text and Value which are /// implemented as dependent properties. /// private bool ShouldSerializeText() { return (text != null) && (text.Length != 0); } ////// Do not change the signature or remove this method. It is called via reflection /// to support correct serialization behavior for Text and Value which are /// implemented as dependent properties. /// private bool ShouldSerializeValue() { return (value != null) && (value.Length != 0); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Globalization; using AttributeCollection = System.Web.UI.AttributeCollection; using System.Security.Permissions; using System.Web.Util; ////// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public class ListItemControlBuilder : ControlBuilder { public override bool AllowWhitespaceLiterals() { return false; } public override bool HtmlDecodeLiterals() { // ListItem text gets rendered as an encoded attribute value. // At parse time text specified as an attribute gets decoded, and so text specified as a // literal needs to go through the same process. return true; } } ///Interacts with the parser to build a ///control. /// [ ControlBuilderAttribute(typeof(ListItemControlBuilder)), TypeConverterAttribute(typeof(ExpandableObjectConverter)), ParseChildren(true, "Text"), ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class ListItem : IStateManager, IParserAccessor, IAttributeAccessor { private bool selected; private bool marked; private bool textisdirty; private bool valueisdirty; private bool enabled; private bool enabledisdirty; private string text; private string value; private AttributeCollection _attributes; ///Constructs a list item control and defines /// its properties. This class cannot be inherited. ////// public ListItem() : this(null, null) { } ///Initializes a new instance of the ///class. /// public ListItem(string text) : this(text, null) { } ///Initializes a new instance of the ///class with the specified text data. /// public ListItem(string text, string value) : this(text, value, true) { } ///Initializes a new instance of the ///class with the specified text data. /// public ListItem(string text, string value, bool enabled) { this.text = text; this.value = value; this.enabled = enabled; } ///Initializes a new instance of the ///class with the /// specified text and value data. /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden) ] public AttributeCollection Attributes { get { if (_attributes == null) _attributes = new AttributeCollection(new StateBag(true)); return _attributes; } } ///Gets the collection of attribute name/value pairs expressed on the list item /// control but not supported by the control's strongly typed properties. ////// Internal property used to manage dirty state of ListItem. /// internal bool Dirty { get { return (textisdirty || valueisdirty || enabledisdirty); } set { textisdirty = value; valueisdirty = value; enabledisdirty = value; } } [ DefaultValue(true) ] public bool Enabled { get { return enabled; } set { enabled = value; if (((IStateManager)this).IsTrackingViewState) enabledisdirty = true; } } internal bool HasAttributes { get { return _attributes != null && _attributes.Count > 0; } } ////// [ DefaultValue(false), TypeConverter(typeof(MinimizableAttributeTypeConverter)) ] public bool Selected { get { return selected; } set { selected = value; } } ///Specifies a value indicating whether the /// item is selected. ////// [ Localizable(true), DefaultValue(""), PersistenceMode(PersistenceMode.EncodedInnerDefaultProperty) ] public string Text { get { if (text != null) return text; if (value != null) return value; return String.Empty; } set { text = value; if (((IStateManager)this).IsTrackingViewState) textisdirty = true; } } ///Gets or sets the display text of the list /// item control. ////// [ Localizable(true), DefaultValue("") ] public string Value { get { if (value != null) return value; if (text != null) return text; return String.Empty; } set { this.value = value; if (((IStateManager)this).IsTrackingViewState) valueisdirty =true; } } ///Gets or sets the value content of the list item control. ///public override int GetHashCode() { return HashCodeCombiner.CombineHashCodes(Value.GetHashCode(), Text.GetHashCode()); } /// /// /// public override bool Equals(object o) { ListItem other = o as ListItem; if (other != null) { return Value.Equals(other.Value) && Text.Equals(other.Text); } return false; } ////// public static ListItem FromString(string s) { return new ListItem(s); } ///Creates a ///from the specified string. /// /// public override string ToString() { return this.Text; } ////// /// Return true if tracking state changes. /// Method of private interface, IStateManager. /// bool IStateManager.IsTrackingViewState { get { return marked; } } ///void IStateManager.LoadViewState(object state) { LoadViewState(state); } internal void LoadViewState(object state) { if (state != null) { if (state is Triplet) { Triplet t = (Triplet) state; if (t.First != null) { Text = (string) t.First; } if (t.Second != null) { Value = (string) t.Second; } if (t.Third != null) { try { Enabled = (bool) t.Third; } catch { } } } else if (state is Pair) { Pair p = (Pair) state; if (p.First != null) Text = (string) p.First; Value = (string) p.Second; } else Text = (string) state; } } /// void IStateManager.TrackViewState() { TrackViewState(); } internal void TrackViewState() { marked = true; } internal void RenderAttributes(HtmlTextWriter writer) { if (_attributes != null) { _attributes.AddAttributes(writer); } } /// object IStateManager.SaveViewState() { return SaveViewState(); } internal object SaveViewState() { string text = null; string value = null; if(textisdirty) { text = Text; } if(valueisdirty) { value = Value; } if(enabledisdirty) { return new Triplet(text, value, Enabled); } else if(valueisdirty) { return new Pair(text, value); } else if(textisdirty) { return text; } return null; } /// /// /// Returns the attribute value of the list item control /// having the specified attribute name. /// string IAttributeAccessor.GetAttribute(string name) { return Attributes[name]; } ////// /// void IAttributeAccessor.SetAttribute(string name, string value) { Attributes[name] = value; } ///Sets an attribute of the list /// item control with the specified name and value. ////// /// void IParserAccessor.AddParsedSubObject(object obj) { if (obj is LiteralControl) { Text = ((LiteralControl)obj).Text; } else { if (obj is DataBoundLiteralControl) { throw new HttpException(SR.GetString(SR.Control_Cannot_Databind, "ListItem")); } else { throw new HttpException(SR.GetString(SR.Cannot_Have_Children_Of_Type, "ListItem", obj.GetType().Name.ToString(CultureInfo.InvariantCulture))); } } } ///Allows the ////// property to be persisted as inner content. /// Do not change the signature or remove this method. It is called via reflection /// to support correct serialization behavior for Text and Value which are /// implemented as dependent properties. /// private void ResetText() { Text = null; } ////// Do not change the signature or remove this method. It is called via reflection /// to support correct serialization behavior for Text and Value which are /// implemented as dependent properties. /// private void ResetValue() { Value = null; } ////// Do not change the signature or remove this method. It is called via reflection /// to support correct serialization behavior for Text and Value which are /// implemented as dependent properties. /// private bool ShouldSerializeText() { return (text != null) && (text.Length != 0); } ////// Do not change the signature or remove this method. It is called via reflection /// to support correct serialization behavior for Text and Value which are /// implemented as dependent properties. /// private bool ShouldSerializeValue() { return (value != null) && (value.Length != 0); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HtmlTableRow.cs
- DateTimeConverter.cs
- xmlsaver.cs
- _SSPISessionCache.cs
- ResourceExpressionEditorSheet.cs
- Command.cs
- Compiler.cs
- XmlSchemaAttributeGroup.cs
- ProcessHost.cs
- Converter.cs
- DynamicILGenerator.cs
- GridViewCellAutomationPeer.cs
- DesignSurface.cs
- AxHost.cs
- TextRenderer.cs
- EntityDataSourceSelectedEventArgs.cs
- ItemCollection.cs
- ControlCachePolicy.cs
- StylusPointPropertyInfoDefaults.cs
- Size3DValueSerializer.cs
- ClientProxyGenerator.cs
- COM2Enum.cs
- HighlightOverlayGlyph.cs
- BrushMappingModeValidation.cs
- ApplicationContext.cs
- GetPageNumberCompletedEventArgs.cs
- SafeLocalMemHandle.cs
- TreeView.cs
- FormatException.cs
- Polyline.cs
- CommonRemoteMemoryBlock.cs
- DataAdapter.cs
- Util.cs
- TemplateNameScope.cs
- OleServicesContext.cs
- WCFServiceClientProxyGenerator.cs
- TraceListeners.cs
- Latin1Encoding.cs
- safelink.cs
- OneOfTypeConst.cs
- X509ChainElement.cs
- PrinterResolution.cs
- RightsManagementEncryptedStream.cs
- ActivityCollectionMarkupSerializer.cs
- ContentTextAutomationPeer.cs
- SafeHandle.cs
- SqlFunctions.cs
- DbConnectionStringCommon.cs
- SID.cs
- ZipPackage.cs
- DoubleLinkListEnumerator.cs
- DefaultDiscoveryServiceExtension.cs
- HtmlSelect.cs
- DataGridViewCellValidatingEventArgs.cs
- TypeGeneratedEventArgs.cs
- AnnotationAdorner.cs
- HtmlInputControl.cs
- ListenerConfig.cs
- FontStretchConverter.cs
- DateTimeSerializationSection.cs
- ReturnValue.cs
- Point3DAnimation.cs
- TemplateBamlTreeBuilder.cs
- PageEventArgs.cs
- ApplicationContext.cs
- XmlIncludeAttribute.cs
- FrameworkElementFactoryMarkupObject.cs
- ExpressionWriter.cs
- NumberFunctions.cs
- HtmlInputImage.cs
- httpstaticobjectscollection.cs
- ProcessHostFactoryHelper.cs
- ObjectListCommandsPage.cs
- ProxyElement.cs
- OciHandle.cs
- ThemeableAttribute.cs
- XmlSchemaElement.cs
- CategoryGridEntry.cs
- DataGrid.cs
- PageCodeDomTreeGenerator.cs
- DataGridRowHeader.cs
- DurationConverter.cs
- ChameleonKey.cs
- CFStream.cs
- ThicknessConverter.cs
- ApplicationInfo.cs
- GraphicsPath.cs
- WebEvents.cs
- FontFamily.cs
- EmptyCollection.cs
- IdentitySection.cs
- Attributes.cs
- FontDialog.cs
- TextRangeSerialization.cs
- SudsParser.cs
- ObjectSecurity.cs
- ServiceOperationInfoTypeConverter.cs
- SqlRowUpdatedEvent.cs
- TextBoxRenderer.cs
- PropertyPathConverter.cs