【发布时间】:2020-12-17 14:40:13
【问题描述】:
我有一个名为 AegHero 的 ASCX 文件,其中有一个 WebPart 的标记。我还有一个 BackgroundColor 属性,其中包含一个类名,该类名对应于具有特定背景颜色的类。
我认为我的问题是我没有正确定义后面代码中的值。我正在使用下拉菜单让用户选择颜色:
这是我的 AegHero.ascx:
<asp:PlaceHolder runat="server">
<div id="mainHeroContainer" class="fullWidth-hero-container <%= BackgroundColor %>">
<div class="fullWidth-hero-container-inner">
<h2 class="fillWidth-hero-title"><%=Title %></h2>
<p class="fillWidth-hero-subtilte"><%=SubTitle %></p>
<% if (ShowButton)
{%>
<a class="btn button" href="<%= ButtonUrl %>"><%= ButtonLabel %></a>
<%} %>
</div>
</div>
</asp:PlaceHolder>
这是我的代码:
public partial class AegHero : GenericWebPart
{
protected string Title => Html("Title", string.Empty);
protected string SubTitle => Html("subTitle", string.Empty);
protected bool ShowButton => GetBooleanValue("ShowButton", false);
protected string ButtonUrl => StringProperty("ButtonUrl", string.Empty);
protected string ButtonLabel => StringProperty("ButtonLabel", string.Empty);
protected string BackgroundColor
{
get { return StringProperty("BackgroundColor", string.Empty); }
set { BackgroundColor = value; }
}
public override void OnContentLoaded()
{
base.OnContentLoaded();
if (BackgroundColor.CompareTo("#002147") == 0)
{
BackgroundColor = "perussian-backGround";
}
else if (BackgroundColor.CompareTo("#0077c2") == 0)
{
BackgroundColor = "lochmara-backGround";
}
else if (BackgroundColor.CompareTo("#858e99") == 0)
{
BackgroundColor = "gray-backGround";
}
}
}
}
这是我的 css 类:
.gray-backGround {
background: #858e99;
}
.lochmara-backGround {
background: #0077c2;
}
.perussian-backGround {
background: #002147;
}
我正在尝试根据我收到的十六进制值设置<%= BackgroundColor %>;但是,当我查看我的 chrome 检查器时,类并没有改变。如何从 backgroundColor 属性中正确获取值并将其设置为 <div>?
Chrome 检查器:
【问题讨论】: