Control.IsLiteralContent 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定服务器控件是否只包含文字内容。
protected:
bool IsLiteralContent();
protected bool IsLiteralContent ();
member this.IsLiteralContent : unit -> bool
Protected Function IsLiteralContent () As Boolean
返回
如果服务器控件只包含文本内容,则为 true
;否则为 false
。
示例
以下示例检查包含服务器控件的页面是否已回发。 如果控件包含,则调用 IsLiteralContent 该方法来确定控件是否只包含文本内容,还是其他服务器控件的父控件。 如果它只包含文本内容,则UniqueIDLiteralControl表示该内容的属性将写入响应。
// 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
时,服务器控件的集合包含单个文本控件。