ASP.Net不正确的背景图片呈现的风格 [英] ASP.Net incorrect background image style rendered
问题描述
使用ASP.Net,我有,我想补充的内联CSS样式背景图片:无的服务器控件。然而,当我打电话:
Using ASP.Net, I have a server control for which i would like to add the inline css style "background-image:none". However, when i call:
writer.AddStyleAttribute("background-image", "none");
下面内嵌样式生成(并试图解析URL无):
The following inline style is generated (and tries to resolve the url "none"):
background-image:url(none)
有一个特殊的语法我可以使用背景图片设置为none内联?
Is there a special syntax I can use to set the background image to none inline?
推荐答案
纵观code为的HtmlTextWriter
和 CssTextWriter 在.net反射,我能想到的是子类
的HtmlTextWriter
自己。
Looking at the code for the HTMLTextWriter
and CssTextWriter
classes in .NET Reflector, the only thing I can think of is subclassing HTMLTextWriter
yourself.
二进制不是在风格枚举的第一个元素〜HtmlTextWriterStyle.BackgroundColor
,就是它使用任何风格的名字不承认,因此,不会刻意去检查,如果该值需要包裹在URL()时,它实际上写出来。
"Binary not the first element in the style enum", ~HtmlTextWriterStyle.BackgroundColor
, is what it uses for any style whose name it doesn't recognize, and therefore doesn't bother to check if the value needs wrapped in "url()" when it's actually written out.
HtmlTextWriterEx
不是最伟大的名字,但不管。 (?)根据你在做什么,你可能需要做这样的事情在你的code-背后 System.Web.UI.Page
子类:
HtmlTextWriterEx
isn't the greatest name, but whatever. Depending on what you're doing, you might(?) need to do something like this in your code-behind System.Web.UI.Page
subclass:
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
return new HtmlTextWriterEx(writer);
}
和这里的类:
class HtmlTextWriterEx : HtmlTextWriter
{
public HtmlTextWriterEx(TextWriter writer)
: this(writer, "\t")
{
}
public HtmlTextWriterEx(TextWriter writer, string tabString)
: base(writer, tabString)
{
}
public override void AddStyleAttribute(string name, string value)
{
if (name.ToLower() == "background-image" && value.ToLower() == "none")
base.AddStyleAttribute(name, value, ~HtmlTextWriterStyle.BackgroundColor);
else
base.AddStyleAttribute(name, value);
}
public override void AddStyleAttribute(HtmlTextWriterStyle key, string value)
{
if(key == HtmlTextWriterStyle.BackgroundImage && value.ToLower() == "none")
base.AddStyleAttribute("background-image", value, ~HtmlTextWriterStyle.BackgroundColor);
else
base.AddStyleAttribute(key, value);
}
}
这篇关于ASP.Net不正确的背景图片呈现的风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!