SearchForKnowledge
SearchForKnowledge

Reputation: 3751

How to add a control from code-behind in a DIV

I have the following code in my MasterPage:

<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="upTaskStatus" ClientIDMode="Static">
    <ContentTemplate>
        <asp:Panel ID="Panel101" runat="server" CssClass="navInnerDiv" Width="100px" ClientIDMode="Static">
            <asp:Panel ID="Panel102" runat="server" CssClass="navInnerDivContents">
                <asp:Panel ID="Panel103" runat="server" CssClass="navInnerDivContentsTop">
                    <asp:Label ID="lblTempHolder" runat="server" Text="" ClientIDMode="Static"></asp:Label>
                </asp:Panel>
                <asp:Panel ID="Panel106" runat="server" CssClass="navInnerDivContentsBottom">
                    Task Status
                </asp:Panel>
            </asp:Panel>
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>

I am trying to add a DIV{panel} from code behind inside Panel103.

I added the following in my Content page:

strCO = @"<asp:Panel ID='Panel100' runat='server' CssClass='navInnerDivContentsTopSubTwo'>
                        <asp:ImageButton ID='ibCheckOut' ImageUrl='~/theImages/CheckOut.png\' runat='server' CssClass='navImages' OnClick='btnComplete_Click' />
                        <br />
                        <asp:LinkButton ID='lbCheckOut' runat='server' Text='Checkout' ClientIDMode='Static' OnClick='btnComplete_Click' CssClass='linkOff' />
                    </asp:Panel>";

System.Web.UI.WebControls.Label pnlTaskS = (System.Web.UI.WebControls.Label)Master.FindControl("lblTempHolder");
            pnlTaskS.Text = strCO;

            System.Web.UI.UpdatePanel upT = (System.Web.UI.UpdatePanel)Master.FindControl("upTaskStatus");
            upT.Update();

When I check the page source, I can see the strCO generated but the Image nor the LinkButton is shown to the front-end.

How can I modify my code to achieve adding a DIV{panel} from code-behind?

Upvotes: 1

Views: 2517

Answers (1)

brz
brz

Reputation: 6016

Create the control in every postback and add it to Panel103:

public void Page_Load(object sender, EventArgs e)
{
   var pnl = new Panel { ID = "Panel100" };
   pnl.Controls.Add(new ImageButton());
   Panel103.Controls.Add(pnl);
}

Upvotes: 1

Related Questions