Control.IsLiteralContent 方法

定義

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

C#
protected bool IsLiteralContent();

傳回

如果伺服器控制項只含有常值內容,則為 true,否則為 false

範例

下列範例會檢查包含伺服器控制項的頁面是否已回傳。 如果有的話,它會呼叫 IsLiteralContent 方法來判斷控制項是否只包含常值內容,或是其他伺服器控制項的父控制項。 如果它只包含常值內容, UniqueID 表示該內容的 屬性 LiteralControl 會寫入回應。

C#
// 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.");
                }
        }
}

備註

當這個方法傳 true 回 時,伺服器控制項的集合會保留單一常值控制項。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

另請參閱