Compartilhar via


UpdatePanel.CreateContentTemplateContainer Método

Definição

Cria um objeto Control que funciona como um contêiner para os controles filho que definem o conteúdo do controle UpdatePanel.

protected:
 virtual System::Web::UI::Control ^ CreateContentTemplateContainer();
protected virtual System.Web.UI.Control CreateContentTemplateContainer ();
abstract member CreateContentTemplateContainer : unit -> System.Web.UI.Control
override this.CreateContentTemplateContainer : unit -> System.Web.UI.Control
Protected Overridable Function CreateContentTemplateContainer () As Control

Retornos

Control

Um contêiner Control para o conteúdo do controle UpdatePanel.

Exemplos

O exemplo a seguir mostra como substituir o CreateContentTemplateContainer método em um controle personalizado UpdatePanel para sempre renderizar os elementos e <legend> o <fieldset> conteúdo do painel. O controle personalizado UpdatePanel define uma propriedade pública chamada GroupingText literal de cadeia de caracteres dentro do <legend> elemento.

Um controle personalizado UpdatePanel nomeado CustomUpdatePanel deriva UpdatePanel e substitui o CreateContentTemplateContainer método. Coloque o CustomUpdatePanel código-fonte da classe na pasta App_Code do site.

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SamplesCS
{
    public class CustomUpdatePanel : System.Web.UI.UpdatePanel
    {
        public CustomUpdatePanel()
        {
        }

        private String _groupingText;
        public String GroupingText
        {
            get { return _groupingText; }
            set { _groupingText = value; }
        }

        protected override Control CreateContentTemplateContainer()
        {
            MyContentTemplateContainer myContentTemplateContainer =
                new MyContentTemplateContainer(_groupingText);
            return myContentTemplateContainer;
        }
        private sealed class MyContentTemplateContainer : Control
        {
            private String _displayText;
            public MyContentTemplateContainer(string groupingText)
            {
                _displayText = groupingText;
            }
            protected override void Render(HtmlTextWriter writer)
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Fieldset);
                writer.RenderBeginTag(HtmlTextWriterTag.Legend);
                writer.Write(_displayText);
                writer.RenderEndTag();
                base.Render(writer);
                writer.RenderEndTag();
            }
        }
    }
}
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace SamplesVB
    Public Class CustomUpdatePanel : Inherits System.Web.UI.UpdatePanel

        Public CustomUpdatePanel()

        Private _groupingText As String

        Public Property GroupingText() As String
            Get
                Return _groupingText
            End Get
            Set(ByVal value As String)
                _groupingText = value
            End Set
        End Property

        Protected Overrides Function CreateContentTemplateContainer() As Control
            Dim myContentTemplateContainer As MyContentTemplateContainer
            myContentTemplateContainer = New MyContentTemplateContainer(_groupingText)
            Dim myControl As Control
            myControl = myContentTemplateContainer
            Return myControl
        End Function

        Private NotInheritable Class MyContentTemplateContainer : Inherits Control

            Private _displayText As String
            Public Sub New(ByVal groupingText As String)
                _displayText = groupingText
            End Sub

            Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

                writer.RenderBeginTag(HtmlTextWriterTag.Fieldset)
                writer.RenderBeginTag(HtmlTextWriterTag.Legend)
                writer.Write(_displayText)
                writer.RenderEndTag()
                MyBase.Render(writer)
                writer.RenderEndTag()
            End Sub

        End Class
    End Class
End Namespace

O controle personalizado UpdatePanel é usado na página da mesma forma que o UpdatePanel controle. O exemplo a seguir mostra uma página que contém o controle personalizado UpdatePanel .

<%@ Page Language="C#" %>
<%@ Register Namespace="SamplesCS" TagPrefix="Samples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateContentTemplateContainer Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1"
                           runat="server" />
        <Samples:CustomUpdatePanel ID="UpdatePanel1"
                                   UpdateMode="Conditional"
                                   GroupingText="This is an UpdatePanel."
                                   runat="server">
            <ContentTemplate>
                <asp:Calendar ID="Calendar1"
                              runat="server" />
            </ContentTemplate>
        </Samples:CustomUpdatePanel>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register Namespace="SamplesCS" TagPrefix="Samples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CreateContentTemplateContainer Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1"
                           runat="server" />
        <Samples:CustomUpdatePanel ID="UpdatePanel1"
                                   UpdateMode="Conditional"
                                   GroupingText="This is an UpdatePanel."
                                   runat="server">
            <ContentTemplate>
                <asp:Calendar ID="Calendar1"
                              runat="server" />
            </ContentTemplate>
        </Samples:CustomUpdatePanel>
    </div>
    </form>
</body>
</html>

Comentários

Esse método destina-se a ser usado por desenvolvedores de controle que desejam estender o UpdatePanel controle. Por exemplo, em classes derivadas, você pode fornecer um controle raiz diferente que atua como um contêiner para o conteúdo do controle UpdatePanel . A implementação padrão retorna um Control objeto.

Aplica-se a

Confira também