ITextControl.Text 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定控制項的文字內容。
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。 同時也提供驗證伺服器控制以評估使用者輸入。 欲了解更多資訊,請參閱 驗證伺服器控制語法。