Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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;
}
}
///
/// Defines the properties and methods of the DataBoundLiteralControl class.
///
[
ToolboxItem(false)
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class DataBoundLiteralControl : Control, ITextControl {
private string[] _staticLiterals;
private string[] _dataBoundLiteral;
private bool _hasDataBoundStrings;
///
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;
}
///
/// Gets the text content of the data-bound literal control.
///
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();
}
}
///
protected override ControlCollection CreateControlCollection() {
return new EmptyControlCollection(this);
}
///
///
/// Loads the previously saved state. Overridden to synchronize Text property with
/// LiteralContent.
///
protected override void LoadViewState(object savedState) {
if (savedState != null) {
_dataBoundLiteral = (string[]) savedState;
_hasDataBoundStrings = true;
}
}
///
///
/// The object that contains the state changes.
///
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;
}
///
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]);
}
}
///
///
/// Implementation of TextControl.Text property.
///
string ITextControl.Text {
get {
return Text;
}
set {
throw new NotSupportedException();
}
}
}
///
/// Simpler version of DataBoundLiteralControlBuilder, used at design time.
///
[
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();
}
///
/// Gets or sets the text content of the data-bound literal control.
///
public string Text {
get {
return _text;
}
set {
_text = (value != null) ? value : String.Empty;
}
}
protected override ControlCollection CreateControlCollection() {
return new EmptyControlCollection(this);
}
///
/// Loads the previously saved state. Overridden to synchronize Text property with
/// LiteralContent.
///
protected override void LoadViewState(object savedState) {
if (savedState != null)
_text = (string) savedState;
}
///
/// Saves any state that was modified after the control began monitoring state changes.
///
protected internal override void Render(HtmlTextWriter output) {
output.Write(_text);
}
///
/// The object that contains the 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.
//
//-----------------------------------------------------------------------------
/*
* 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;
}
}
///
/// Defines the properties and methods of the DataBoundLiteralControl class.
///
[
ToolboxItem(false)
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class DataBoundLiteralControl : Control, ITextControl {
private string[] _staticLiterals;
private string[] _dataBoundLiteral;
private bool _hasDataBoundStrings;
///
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;
}
///
/// Gets the text content of the data-bound literal control.
///
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();
}
}
///
protected override ControlCollection CreateControlCollection() {
return new EmptyControlCollection(this);
}
///
///
/// Loads the previously saved state. Overridden to synchronize Text property with
/// LiteralContent.
///
protected override void LoadViewState(object savedState) {
if (savedState != null) {
_dataBoundLiteral = (string[]) savedState;
_hasDataBoundStrings = true;
}
}
///
///
/// The object that contains the state changes.
///
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;
}
///
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]);
}
}
///
///
/// Implementation of TextControl.Text property.
///
string ITextControl.Text {
get {
return Text;
}
set {
throw new NotSupportedException();
}
}
}
///
/// Simpler version of DataBoundLiteralControlBuilder, used at design time.
///
[
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();
}
///
/// Gets or sets the text content of the data-bound literal control.
///
public string Text {
get {
return _text;
}
set {
_text = (value != null) ? value : String.Empty;
}
}
protected override ControlCollection CreateControlCollection() {
return new EmptyControlCollection(this);
}
///
/// Loads the previously saved state. Overridden to synchronize Text property with
/// LiteralContent.
///
protected override void LoadViewState(object savedState) {
if (savedState != null)
_text = (string) savedState;
}
///
/// Saves any state that was modified after the control began monitoring state changes.
///
protected internal override void Render(HtmlTextWriter output) {
output.Write(_text);
}
///
/// The object that contains the state changes.
///
protected override object SaveViewState() {
return _text;
}
}
}
// 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
- X509SecurityToken.cs
- WmpBitmapDecoder.cs
- ExpressionBuilder.cs
- RowTypePropertyElement.cs
- SynchronizedDispatch.cs
- ActionNotSupportedException.cs
- FilterRepeater.cs
- RuntimeTrackingProfile.cs
- PeerNearMe.cs
- QilInvokeEarlyBound.cs
- Timer.cs
- TimeManager.cs
- XmlAttributeCollection.cs
- SystemIcmpV4Statistics.cs
- Label.cs
- SchemaTableOptionalColumn.cs
- TrackBar.cs
- CallSite.cs
- GroupJoinQueryOperator.cs
- JsonWriter.cs
- LineGeometry.cs
- WebEventCodes.cs
- WebPartUtil.cs
- FlowLayoutPanel.cs
- Matrix3D.cs
- HyperLinkStyle.cs
- Stacktrace.cs
- DataBindingExpressionBuilder.cs
- ProfileInfo.cs
- ArrangedElement.cs
- DataGridViewRowPrePaintEventArgs.cs
- ScriptControlManager.cs
- SQLInt16Storage.cs
- IdentityHolder.cs
- DataServiceRequest.cs
- FrameworkContentElementAutomationPeer.cs
- RequestCache.cs
- TimeSpanValidator.cs
- SerializeAbsoluteContext.cs
- HyperlinkAutomationPeer.cs
- OutputScope.cs
- PropertySourceInfo.cs
- AutomationPatternInfo.cs
- WorkflowRuntimeSection.cs
- TrackingServices.cs
- DrawingServices.cs
- PersonalizableTypeEntry.cs
- WindowsStartMenu.cs
- remotingproxy.cs
- JsonReaderWriterFactory.cs
- DiscardableAttribute.cs
- UICuesEvent.cs
- SqlBulkCopy.cs
- Literal.cs
- IntSecurity.cs
- WmpBitmapEncoder.cs
- OuterGlowBitmapEffect.cs
- TrustLevelCollection.cs
- MouseOverProperty.cs
- ZoneIdentityPermission.cs
- ScriptResourceDefinition.cs
- ByteConverter.cs
- ChannelSinkStacks.cs
- SqlParameterCollection.cs
- HttpRuntime.cs
- Expressions.cs
- SelectionItemProviderWrapper.cs
- SafeFileMappingHandle.cs
- SpellerInterop.cs
- TimeManager.cs
- ControlParameter.cs
- ParameterElementCollection.cs
- CommonDialog.cs
- WebExceptionStatus.cs
- Point3DAnimationBase.cs
- EntityFrameworkVersions.cs
- LabelEditEvent.cs
- RegexTree.cs
- MetadataItemSerializer.cs
- BuildDependencySet.cs
- SystemWebCachingSectionGroup.cs
- TableLayoutPanelCellPosition.cs
- ClusterRegistryConfigurationProvider.cs
- WmlControlAdapter.cs
- AnonymousIdentificationModule.cs
- HttpClientCertificate.cs
- ConsoleCancelEventArgs.cs
- StringPropertyBuilder.cs
- LocalizableAttribute.cs
- HttpProfileGroupBase.cs
- elementinformation.cs
- DataServiceContext.cs
- NativeMethods.cs
- ChannelCredentials.cs
- SamlConditions.cs
- TemplateInstanceAttribute.cs
- ServiceMoniker.cs
- CommandManager.cs
- ComponentConverter.cs
- TabControlEvent.cs