asp.net - 在代码隐藏中将 CSS 类添加到面板

标签 asp.net css panel code-behind

我在 aspx 页面中有一个看起来像这样的面板:

<asp:Panel ID="popUpPanelSelectFields" runat="server" CssClass="confirm-dialog" BorderColor="Aqua" >   
<div class="inner">
        <h2>hello word</h2>
        <div class="base">
            <br/>
            <asp:Label ID="LabelMessageToTeacher" runat="server" Text="some text" /><br/>
            <asp:TextBox ID="TextBoxMessageToTeacher" runat="server" Width="200px" Height="50px"/><br/><br/>
            <asp:CheckBox ID="CheckBoxSkype" runat="server" Text="some text" /><br/>                
            <asp:CheckBox ID="CheckBoxPhoneNumber" runat="server" Text="some text" /><br/><br/>                                
            <asp:Button ID="ButtonOk" runat="server" Text="Ok" />
        </div>
    </div>
</asp:Panel> 

我想在后面的代码中编写相同的代码,但我的 css 有问题 到目前为止编写的代码:

Panel panel = new panel();
panel .CssClass = "confirm-dialog";
panel BorderColor = System.Drawing.Color.Aqua;   

现在我知道如何添加标签、按钮、复选框和文本框了,但是如何添加“h2” 到标签并用我的 css 文件中的“内部”和“基”类包装控件

谢谢

最佳答案

您需要使用 HtmlElement类。

您可以像使用任何其他控件类一样使用它来构建页面上的元素层次结构:

var div = new HtmlElement("div");
var h2 = new HtmlElement("h2");
var childDiv = new HtmlElment("div");

h2.InnerText = "hello world";

childDiv.Children.Add(LabelMessageToTeacher);
childDiv.Children.Add(TextBoxMessageToTeacher);
// add the rest of the nested controls

div.Children.Add(h2);
div.Children.Add(childDiv); 

关于asp.net - 在代码隐藏中将 CSS 类添加到面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9445338/

相关文章:

c# - 重绘时如何修复面板闪烁?

.net - 如何在 WinForms 中设置面板的不透明度或透明度?

java - 当鼠标悬停在两个面板的交叉区域时更改光标

c# - 在 C# 中不使用 GDI+ 处理图像

c# - 外部身份验证不重定向到外部站点

c# - 只允许 ipad 应用程序用户访问某些文件

c# - asp.net filehelpers 直接写文件到客户端

html - 我应该向 CSS 添加什么属性以使其从页面上的特定位置开始?

html - Magento Foreach 子类别获取产品列表

html - 显示文档 : -webkit-inline-box;