ITextControl 介面

定義

定義控制項要實作的介面,以取得或設定其文字內容。

public interface class ITextControl
public interface ITextControl
type ITextControl = interface
Public Interface ITextControl
衍生

範例

下列程式碼範例示範實作 介面的 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

備註

介面 ITextControlText 定義 控制項實作的屬性,以允許取得或設定其文字內容。 Text屬性可以透過程式設計方式或透過使用者輸入來設定。

警告

實作此介面的控制項可用來顯示使用者輸入。 在顯示使用者輸入之前,必須檢查輸入是否有惡意用戶端腳本,例如可執行腳本或 SQL 語句。 ASP.NET 提供輸入要求驗證功能,以封鎖使用者輸入中的腳本和 HTML。 也會提供驗證服務器控制項來評估使用者輸入。 如需詳細資訊,請參閱 驗證服務器控制項語法

屬性

Text

取得或設定控制項的文字內容。

適用於