locked
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">
     <ContentTemplate>
        SomeContent
     </ContentTemplate>
    </lib:ContainerBox>

    and for example instead of Some Content i have:

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

    and in RenderContents override of my control i have:

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

    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

Answers

  • 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);

    container.Controls.Add(lblItem);

    break;

    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);

    container.Controls.Add(editItemTextBox);

    break;

    default: break;

    }

    }

    here some links for about InstantiateIn ;

    http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.instantiatein.aspx

    http://support.microsoft.com/kb/310898

    i hope these helps you..

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