ITextControl.Text 属性

定义

获取或设置控件的文本内容。Gets or sets the text content of a control.

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

属性值

控件的文本内容。The text content of a control.

示例

下面的代码示例演示实现ITextControl接口的自定义控件。The following code example shows a custom control that implements the ITextControl interface. Text 如果null传递到属性, 则默认值将分配给该属性。A default value is assigned to the Text property if null is passed to the property.


public class CustomTextControl : Control, ITextControl
{
    private string _text;

    public CustomTextControl()
    {
    }

    public string Text
    {
        get
        {
            return _text;
        }
        set
        {
            if (value != null)
            {
                _text = value;
            }
            else
            {
                _text = "No Value.";
            }
        }
    }

    // Provide the remaining code to implement a text control.
}

Public Class CustomTextControl
    Inherits System.Web.UI.Control
    Implements System.Web.UI.ITextControl

    Private _text As String

    Public Property Text() As String Implements System.Web.UI.ITextControl.Text
        Get
            Return _text
        End Get
        Set(ByVal value As String)
            If (value <> Nothing) Then
                _text = value
            Else
                _text = "No Value."
            End If
        End Set
    End Property

    ' Provide the remaining code to implement a text control.
End Class

注解

可以通过编程方式或通过用户输入来设置属性。TextThe Text property can be set programmatically or through user input.

注意

实现此接口的控件可用于显示用户输入。A control implementing this interface can be used to display user input. 在显示用户输入之前, 必须检查输入中是否有恶意的客户端脚本, 如可执行脚本或 SQL 语句。Before displaying user input, the input must be checked for malicious client script, such as executable script or SQL statements. ASP.NET 提供输入请求验证功能来阻止用户输入中的脚本和 HTML。ASP.NET provides an input request validation feature to block script and HTML in user input. 还提供验证服务器控件以评估用户输入。Validation server controls are also provided to assess user input. 有关详细信息, 请参阅验证服务器控制语法For more information, see Validation Server Control Syntax.

适用于