UpdatePanel.ContentTemplateContainer 属性

定义

获取一个可以以编程方式向其添加子控件的控件对象。Gets a control object to which you can programmatically add child controls.

public:
 property System::Web::UI::Control ^ ContentTemplateContainer { System::Web::UI::Control ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.Control ContentTemplateContainer { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ContentTemplateContainer : System.Web.UI.Control
Public ReadOnly Property ContentTemplateContainer As Control

属性值

Control

一个定义了 Control 控件内容的 UpdatePanel 对象。A Control object that defines the content of the UpdatePanel control.

属性

示例

下面的示例演示如何以编程方式指定 ContentTemplateContainer 控件的属性 UpdatePanelThe following example shows how to programmatically specify the ContentTemplateContainer property of an UpdatePanel control. Text Label 当单击时,将设置控件的属性 Button1The Text property of a Label control is set when Button1 is clicked.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        UpdatePanel up1 = new UpdatePanel();
        up1.ID = "UpdatePanel1";
        up1.UpdateMode = UpdatePanelUpdateMode.Conditional;
        Button button1 = new Button();
        button1.ID = "Button1";
        button1.Text = "Submit";
        button1.Click += new EventHandler(Button_Click);
        Label label1 = new Label();
        label1.ID = "Label1";
        label1.Text = "A full page postback occurred.";
        up1.ContentTemplateContainer.Controls.Add(button1);
        up1.ContentTemplateContainer.Controls.Add(label1);
        Page.Form.Controls.Add(up1);
    }
    protected void Button_Click(object sender, EventArgs e)
    {
        ((Label)Page.FindControl("Label1")).Text = "Panel refreshed at " +
            DateTime.Now.ToString();
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1"
                               runat="server" />
        </div>
    </form>
</body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim lbl As Label
        lbl = Page.FindControl("Label1")
        lbl.Text = "Panel refreshed at " & DateTime.Now.ToString()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim up1 As UpdatePanel
        up1 = New UpdatePanel()
        up1.ID = "UpdatePanel1"
        Dim button1 As Button
        button1 = New Button()
        button1.ID = "Button1"
        button1.Text = "Submit"
        AddHandler button1.Click, AddressOf Button_Click
        Dim label1 As Label
        label1 = New Label()
        label1.ID = "Label1"
        label1.Text = "A full page postback occurred."
        up1.ContentTemplateContainer.Controls.Add(button1)
        up1.ContentTemplateContainer.Controls.Add(label1)
        Page.Form.Controls.Add(up1)
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanel Constructor Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
                               runat="server" />
        </div>
    </form>
</body>
</html>

注解

ContentTemplateContainer属性使你能够以编程方式向控件添加子控件, UpdatePanel 而无需定义从接口继承的自定义模板 ITemplateThe ContentTemplateContainer property enables you to programmatically add child controls to the UpdatePanel control without having to define a custom template that inherits from the ITemplate interface. 如果 UpdatePanel 以声明方式或通过设计器将内容添加到控件,则应 ContentTemplate 使用元素向属性添加内容 <ContentTemplate>If you are adding content to the UpdatePanel control declaratively or through a designer, you should add content to the ContentTemplate property by using a <ContentTemplate> element.

适用于

另请参阅