问题描述
|
如何设置HTML正文的属性背景图像
在Asp.Net的皮肤文件中?
我需要的是我需要像Twitter一样更改页面的背景图像...但是要使用皮肤文件...
解决方法
您没有在外观文件中设置该属性,而是在样式文件中设置了该属性
在
App_Themes
内Theme
文件夹下的style.css
中写入属性
body {
background: url(images/path.png) repeat 0 0;
}
,恐怕Skin文件是用于本机Asp.net控件的。
一种选择是即时生成CSS(或已经生成),然后在Code-Behind中为用户加载该CSS。只需将其放在aspx页面/母版页的Head元素中:
<link id=\"Custom_StyleSheet\" runat=\"server\"
rel=\"stylesheet\" type=\"text/css\" href=\"\" />
并将其添加到您的母版页(或常规的Aspx页)中:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (IsPostBack == false)
{
if (boolUseCustomStyleSheet == true)
{
//This is the relative path of your Css file.
Custom_StyleSheet.Href = sColorCssPath;
}
}
}
如果需要更多精细控制,可以将设置为服务器端控件,如下所示:
将更改为:
<body id=\"someBody\" runat=\"server\" >
然后将其添加到您的代码隐藏中:
protected void Page_Load(object sender,EventArgs e)
{
someBody.Style.Add(\"background-color\",\"Silver\");
}
我不推荐使用后一种方法,但是您可以根据个人用户添加样式列表。如果是样式的有限列表,那么我将为每种样式创建CSS,然后像前面的示例一样动态添加样式。