1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
//------------------------------------------------------------------------------
// <copyright file="LiteralControl.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/*
* Control that holds a literal string
*
* Copyright (c) 1999 Microsoft Corporation
*/
namespace System.Web.UI {
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO;
/// <devdoc>
/// <para>Defines the properties and methods of the LiteralControl class. A
/// literal control is usually rendered as HTML text on a page. </para>
/// <para>
/// LiteralControls behave as text holders, i.e., the parent of a LiteralControl may decide
/// to extract its text, and remove the control from its Control collection (typically for
/// performance reasons).
/// Therefore a control derived from LiteralControl must do any preprocessing of its Text
/// when it hands it out, that it would otherwise have done in its Render implementation.
/// </para>
/// </devdoc>
[
ToolboxItem(false)
]
public class LiteralControl : Control, ITextControl {
internal string _text;
/// <devdoc>
/// <para>Creates a control that holds a literal string.</para>
/// </devdoc>
public LiteralControl() {
PreventAutoID();
SetEnableViewStateInternal(false);
}
/// <devdoc>
/// <para>Initializes a new instance of the LiteralControl class with
/// the specified text.</para>
/// </devdoc>
public LiteralControl(string text) : this() {
_text = (text != null) ? text : String.Empty;
}
/// <devdoc>
/// <para>Gets or sets the text content of the literal control.</para>
/// </devdoc>
public virtual string Text {
get {
return _text;
}
set {
_text = (value != null) ? value : String.Empty;
}
}
protected override ControlCollection CreateControlCollection() {
return new EmptyControlCollection(this);
}
/// <devdoc>
/// <para>Saves any state that was modified after mark.</para>
/// </devdoc>
protected internal override void Render(HtmlTextWriter output) {
output.Write(_text);
}
internal override void InitRecursive(Control namingContainer) {
ResolveAdapter();
if (AdapterInternal != null) {
AdapterInternal.OnInit(EventArgs.Empty);
}
else {
OnInit(EventArgs.Empty);
}
}
internal override void LoadRecursive() {
if (AdapterInternal != null) {
AdapterInternal.OnLoad(EventArgs.Empty);
}
else {
OnLoad(EventArgs.Empty);
}
}
internal override void PreRenderRecursiveInternal() {
if (AdapterInternal != null) {
AdapterInternal.OnPreRender(EventArgs.Empty);
}
else {
OnPreRender(EventArgs.Empty);
}
}
internal override void UnloadRecursive(bool dispose) {
if (AdapterInternal != null) {
AdapterInternal.OnUnload(EventArgs.Empty);
}
else {
OnUnload(EventArgs.Empty);
}
//
if (dispose)
Dispose();
}
}
/*
* Class used to access literal strings stored in a resource (perf optimization).
* This class is only public because it needs to be used by the generated classes.
* Users should not use directly.
*/
internal sealed class ResourceBasedLiteralControl : LiteralControl {
private TemplateControl _tplControl;
private int _offset; // Offset of the start of this string in the resource
private int _size; // Size of this string in bytes
private bool _fAsciiOnly; // Does the string contain only 7-bit ascii characters
internal ResourceBasedLiteralControl(TemplateControl tplControl, int offset, int size, bool fAsciiOnly) {
// Make sure we don't access invalid data
if (offset < 0 || offset+size > tplControl.MaxResourceOffset)
throw new ArgumentException();
_tplControl = tplControl;
_offset = offset;
_size = size;
_fAsciiOnly = fAsciiOnly;
PreventAutoID();
EnableViewState = false;
}
public override string Text {
get {
// If it's just a normal string, call the base
if (_size == 0)
return base.Text;
return StringResourceManager.ResourceToString(
_tplControl.StringResourcePointer, _offset, _size);
}
set {
// From now on, this will behave like a normal LiteralControl
_size = 0;
base.Text = value;
}
}
protected internal override void Render(HtmlTextWriter output) {
// If it's just a normal string, call the base
if (_size == 0) {
base.Render(output);
return;
}
output.WriteUTF8ResourceString(_tplControl.StringResourcePointer, _offset, _size, _fAsciiOnly);
}
}
}
|