RenderContents doesn't render events and autopostbacks RRS feed

  • Question

  • User-1036165177 posted

     i have a control for example ContainerBox : UserControl and i have a Template item:

    <lib:ContainerBox runat="server" ID="boxMain">

    and for example instead of Some Content i have:

    <lib:ContainerBox runat="server" ID="boxMain">
        <asp:RadioButtonList ID="drpViewType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="drpViewType_SelectedIndexChanged">
        <asp:ListItem Selected="True">View</asp:ListItem>

    and in RenderContents override of my control i have:

    TemplateItem tiContent = new TemplateItem();
    tiContent.ID = "containerFooter";
    if (_contentTemplate != null)
        output.Write("<div style='padding: 5px 5px 5px 5px;'>");
        foreach (Control ctrl in tiContent.Controls)

    just that, but the rendered output doesn't include post back event of RadioButtonList, and it doesn't post back when i change the selected options.

    I should say TemplateItem is a class that is derived from CompositeControl.
        public class TemplateItem : System.Web.UI.WebControls.CompositeControl

    please help me.

    Wednesday, May 21, 2008 1:26 PM


  • User-667042492 posted

    Maybe this solve your problem,

    Inherit your custom control class from ITemplate and add Itemplate method named

    void ITemplate.InstantiateIn(Control container) .. in this method when you are binding controls in template

    create a new control and add events to this control what you want..

    for example i m using a similar sample in my project,

    void ITemplate.InstantiateIn(Control container)


    switch (templateType) // this is a property in my custom control


    case ListItemType.Item:Label lblItem = new Label();

    lblItem.ID = "lbl" + this.Id;

    lblItem.DataBinding += new EventHandler(lblItem_DataBinding);



    case ListItemType.EditItem:

    TextBox editItemTextBox = new TextBox();

    editItemTextBox.ID = "txt" + this.Id;

    //editItemTextBox.AutoPostBack = true; //if requires intellect update

    editItemTextBox.DataBinding += new EventHandler(editItemTextBox_DataBinding);



    default: break;



    here some links for about InstantiateIn ;



    i hope these helps you..

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 23, 2008 6:06 AM