Share via


ITextControl.Text 属性

定义

获取或设置控件的文本内容。

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

属性值

控件的文本内容。

示例

下面的代码示例演示了实现 接口的 ITextControl 自定义控件。 如果 null 传递给属性,Text则为 属性分配默认值。


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

注解

Text可以通过编程方式或通过用户输入设置 属性。

注意

实现此接口的控件可用于显示用户输入。 在显示用户输入之前,必须检查输入是否存在恶意客户端脚本,例如可执行脚本或 SQL 语句。 ASP.NET 提供了输入请求验证功能,用于阻止用户输入中的脚本和 HTML。 还提供了验证服务器控件来评估用户输入。 有关详细信息,请参阅 验证服务器控件语法

适用于