Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / fx / src / xsp / System / Web / UI / DataBoundLiteralControl.cs / 1 / DataBoundLiteralControl.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Control that holds databinding expressions and literals * * Copyright (c) 1999 Microsoft Corporation */ namespace System.Web.UI { using System; using System.ComponentModel; using System.ComponentModel.Design; using System.IO; using System.Text; using System.Security.Permissions; using System.Web.Util; internal class DataBoundLiteralControlBuilder : ControlBuilder { internal DataBoundLiteralControlBuilder() { } internal void AddLiteralString(string s) { Debug.Assert(!InDesigner, "!InDesigner"); // Make sure strings and databinding expressions alternate object lastBuilder = GetLastBuilder(); if (lastBuilder != null && lastBuilder is string) { AddSubBuilder(null); } AddSubBuilder(s); } internal void AddDataBindingExpression(CodeBlockBuilder codeBlockBuilder) { Debug.Assert(!InDesigner, "!InDesigner"); // Make sure strings and databinding expressions alternate object lastBuilder = GetLastBuilder(); if (lastBuilder == null || lastBuilder is CodeBlockBuilder) { AddSubBuilder(null); } AddSubBuilder(codeBlockBuilder); } internal int GetStaticLiteralsCount() { // it's divided by 2 because half are strings and half are databinding // expressions). '+1' because we always start with a literal string. return (SubBuilders.Count+1) / 2; } internal int GetDataBoundLiteralCount() { // it's divided by 2 because half are strings and half are databinding // expressions) return SubBuilders.Count / 2; } } ////// [ ToolboxItem(false) ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class DataBoundLiteralControl : Control, ITextControl { private string[] _staticLiterals; private string[] _dataBoundLiteral; private bool _hasDataBoundStrings; ///Defines the properties and methods of the DataBoundLiteralControl class. ///public DataBoundLiteralControl(int staticLiteralsCount, int dataBoundLiteralCount) { _staticLiterals = new string[staticLiteralsCount]; _dataBoundLiteral = new string[dataBoundLiteralCount]; PreventAutoID(); } /// public void SetStaticString(int index, string s) { _staticLiterals[index] = s; } /// public void SetDataBoundString(int index, string s) { _dataBoundLiteral[index] = s; _hasDataBoundStrings = true; } /// /// public string Text { get { StringBuilder sb = new StringBuilder(); int dataBoundLiteralCount = _dataBoundLiteral.Length; // Append literal and databound strings alternatively for (int i=0; i<_staticLiterals.Length; i++) { if (_staticLiterals[i] != null) sb.Append(_staticLiterals[i]); // Could be null if DataBind() was not called if (i < dataBoundLiteralCount && _dataBoundLiteral[i] != null) sb.Append(_dataBoundLiteral[i]); } return sb.ToString(); } } ///Gets the text content of the data-bound literal control. ///protected override ControlCollection CreateControlCollection() { return new EmptyControlCollection(this); } /// /// /// protected override void LoadViewState(object savedState) { if (savedState != null) { _dataBoundLiteral = (string[]) savedState; _hasDataBoundStrings = true; } } ///Loads the previously saved state. Overridden to synchronize Text property with /// LiteralContent. ////// /// protected override object SaveViewState() { // Return null if we didn't get any databound strings if (!_hasDataBoundStrings) return null; // Only save the databound literals to the view state return _dataBoundLiteral; } ///The object that contains the state changes. ///protected internal override void Render(HtmlTextWriter output) { int dataBoundLiteralCount = _dataBoundLiteral.Length; // Render literal and databound strings alternatively for (int i=0; i<_staticLiterals.Length; i++) { if (_staticLiterals[i] != null) output.Write(_staticLiterals[i]); // Could be null if DataBind() was not called if (i < dataBoundLiteralCount && _dataBoundLiteral[i] != null) output.Write(_dataBoundLiteral[i]); } } /// /// /// string ITextControl.Text { get { return Text; } set { throw new NotSupportedException(); } } } ///Implementation of TextControl.Text property. ////// [ DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + AssemblyRef.SystemDesign), ToolboxItem(false) ] [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] public sealed class DesignerDataBoundLiteralControl : Control { private string _text; public DesignerDataBoundLiteralControl() { PreventAutoID(); } ///Simpler version of DataBoundLiteralControlBuilder, used at design time. ////// public string Text { get { return _text; } set { _text = (value != null) ? value : String.Empty; } } protected override ControlCollection CreateControlCollection() { return new EmptyControlCollection(this); } ///Gets or sets the text content of the data-bound literal control. ////// protected override void LoadViewState(object savedState) { if (savedState != null) _text = (string) savedState; } ///Loads the previously saved state. Overridden to synchronize Text property with /// LiteralContent. ////// protected internal override void Render(HtmlTextWriter output) { output.Write(_text); } ///Saves any state that was modified after the control began monitoring state changes. ////// protected override object SaveViewState() { return _text; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.The object that contains the state changes. ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataStreamFromComStream.cs
- Visual3D.cs
- XmlSerializer.cs
- QilUnary.cs
- HttpApplication.cs
- DocumentPageTextView.cs
- WasHostedComPlusFactory.cs
- Soap11ServerProtocol.cs
- Point3D.cs
- PasswordRecovery.cs
- SecurityHelper.cs
- NavigationEventArgs.cs
- XsltLoader.cs
- TextRangeAdaptor.cs
- DbQueryCommandTree.cs
- CounterCreationData.cs
- SpanIndex.cs
- BamlResourceSerializer.cs
- ScaleTransform.cs
- ButtonRenderer.cs
- TypeLoadException.cs
- Polyline.cs
- SatelliteContractVersionAttribute.cs
- SystemFonts.cs
- MobileTemplatedControlDesigner.cs
- MailMessageEventArgs.cs
- MethodToken.cs
- FunctionDefinition.cs
- PasswordBoxAutomationPeer.cs
- InvalidCastException.cs
- MetadataItemEmitter.cs
- UriScheme.cs
- SqlProviderUtilities.cs
- XmlSignatureProperties.cs
- ResourceDescriptionAttribute.cs
- ContentOperations.cs
- Debugger.cs
- FontStretches.cs
- PhysicalAddress.cs
- AppDomainManager.cs
- TypeSystem.cs
- IPAddressCollection.cs
- AutomationAttributeInfo.cs
- SafeCancelMibChangeNotify.cs
- MainMenu.cs
- BasicDesignerLoader.cs
- FactoryMaker.cs
- RepeaterDataBoundAdapter.cs
- ProfileService.cs
- AuthenticationConfig.cs
- wpf-etw.cs
- SapiGrammar.cs
- WorkflowOperationFault.cs
- AnyAllSearchOperator.cs
- MetadataProperty.cs
- WebPartMenu.cs
- BitmapEffect.cs
- ToolStripDropDownItem.cs
- KerberosSecurityTokenParameters.cs
- EntityType.cs
- XmlAnyAttributeAttribute.cs
- SystemKeyConverter.cs
- WindowsListBox.cs
- ListBoxAutomationPeer.cs
- PaperSize.cs
- SmiMetaDataProperty.cs
- SharedStatics.cs
- DesignTimeParseData.cs
- WebControlAdapter.cs
- DescendentsWalker.cs
- WebBaseEventKeyComparer.cs
- XPathSelectionIterator.cs
- CodeTypeReference.cs
- DataContext.cs
- Types.cs
- DependencyPropertyKind.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- HuffCodec.cs
- SQLDecimalStorage.cs
- HttpModuleActionCollection.cs
- EllipticalNodeOperations.cs
- FormsAuthentication.cs
- ISAPIRuntime.cs
- FrameworkPropertyMetadata.cs
- UIElement3D.cs
- RequestQueryProcessor.cs
- SystemIPv4InterfaceProperties.cs
- DataGridItemEventArgs.cs
- NetCodeGroup.cs
- ImageCodecInfoPrivate.cs
- PageBuildProvider.cs
- XmlnsCache.cs
- SoapAttributeOverrides.cs
- SubMenuStyleCollectionEditor.cs
- GlobalizationAssembly.cs
- SingleKeyFrameCollection.cs
- TextTreeObjectNode.cs
- NavigationPropertyEmitter.cs
- CacheVirtualItemsEvent.cs
- MD5CryptoServiceProvider.cs