【发布时间】:2012-01-07 11:48:41
【问题描述】:
好的,我创建了如下所示的简单用户控件
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PlaceHolderCMS.ascx.cs" Inherits="Controls_PlaceHolderCMS" %>
<div id="contentPlaceholder" runat="server" class="contentPlaceholderStyle">
</div>
我就是这样用的
<div class="mainField" runat="server">
<cms:PlaceHolder ID="PlaceHolderCMS1" runat="server" class="PH1" />
<cms:PlaceHolder ID="PlaceHolderCMS2" runat="server" />
</div>
但我的问题是 CSS,我可以编辑与整个控件相关联的样式,像这样
.contentPlaceholderStyle
{
border-style :dashed;
background-color:transparent;
border-width:1px;
padding: 10px, 10px, 0px, 0px;
margin:15px;
height:100px;
}
但是当我尝试为用户控件的单个实例设置样式时,什么都没有发生。我从样式表中尝试了这个,就像这样
.PH1
{
height:100px;
}
来自 C#,像这样 protected void Page_Load(object sender, EventArgs e)
{
PlaceHolderCMS1.Attributes["style"] = "width=" + width + "%; height:" + height + "px;" ;
}
所以我的问题是如何为自定义控件的实例添加样式属性?我想为整个控件设置通用样式,并在需要时为特定实例覆盖它们。
提前谢谢你....
【问题讨论】:
标签: asp.net css custom-controls instance