如何在DIV中添加代码隐藏控件

时间:2014-09-03 21:26:07

标签: c# css asp.net updatepanel panel

我在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>

我正在尝试从Panel103内的代码中添加DIV {panel}。

我在“内容”页面中添加了以下内容:

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

当我检查页面源时,我可以看到strCO已生成,但Image和LinkBut​​ton都显示在前端。

如何修改代码以实现从代码隐藏中添加DIV {panel}?

1 个答案:

答案 0 :(得分:1)

在每个回发中创建控件并将其添加到Panel103:

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