Page.FindControl only works for server controls. You assign an identifier for the text in a literal control, which is a div, but not the control itself. If you set the ID of the control, you can find it, but I don’t know what you intend.
HTML. , runat = , ASP.NET , . - , , Page.FindControl . "declarepanel" aspx. ClientIdMode.Static , ASP.NET (, "MainContent_childPanel" )
<asp:Panel ID="declaredPanel" runat="server" ClientIDMode="Static" />
Page_Load:
Panel p = new Panel();
p.Style["background-color"] = "#aaeeaa";
p.ID = "childPanel";
p.ClientIDMode = System.Web.UI.ClientIDMode.Static;
p.Controls.Add(new LiteralControl("<div id=\"div111\" runat=\"server\">Hello, world!</div>"));
declaredPanel.Controls.Add(p);
Panel p2 = declaredPanel.FindControl("childPanel") as Panel;
string colorCode = p2.Style["background-color"];
:
<div id="declaredPanel">
<div id="childPanel" style="background-color:#aaeeaa;">
<div id="div111" runat="server">Hello, world!</div>
</div>
</div>