共用方式為


Control.IsLiteralContent 方法

定義

判斷伺服器控制項是否只儲存常值內容。

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 回 時,伺服器控制項的集合會保留單一常值控制項。

適用於

另請參閱