Control.IsLiteralContent 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
判斷伺服器控制項是否只儲存常值內容。
protected:
bool IsLiteralContent();
protected bool IsLiteralContent ();
member this.IsLiteralContent : unit -> bool
Protected Function IsLiteralContent () As Boolean
傳回
如果伺服器控制項只含有常值內容,則為 true
,否則為 false
。
範例
下列範例會檢查包含伺服器控制項的頁面是否已回傳。 如果有的話,它會呼叫 IsLiteralContent 方法來判斷控制項是否只包含常值內容,或是其他伺服器控制項的父控制項。 如果它只包含常值內容, UniqueID 表示該內容的 屬性 LiteralControl 會寫入回應。
// Override the OnLoad method to check if the
// page that uses this control has posted back.
// If so, check whether this controls contains
// only literal content, and if it does,
// it gets the UniqueID property and writes it
// to the page. Otherwise, it writes a message
// that the control contains more than literal content.
protected override void OnLoad(EventArgs e)
{
if (Page.IsPostBack)
{
String s;
if (this.IsLiteralContent())
{
s = Controls[0].UniqueID;
Context.Response.Write(s);
}
else
{
Context.Response.Write(
"The control contains more than literal content.");
}
}
}
' Override the OnLoad method to check if the
' page that uses this control has posted back.
' If so, check whether this controls contains
' only literal content, and if it does,
' it gets the UniqueID property and writes it
' to the page. Otherwise, it writes a message
' that the control contains more than literal content.
Overrides Protected Sub OnLoad(ByVal e As EventArgs)
If Page.IsPostBack = True Then
Dim s As String
If Me.IsLiteralContent() = True Then
s = Controls(0).UniqueID
Context.Response.Write(s)
Else
Context.Response.Write( _
"The control contains more than literal content.")
End If
End If
End Sub
備註
當這個方法傳 true
回 時,伺服器控制項的集合會保留單一常值控制項。