Looking at the code for the HTMLTextWriter and CssTextWriter in .NET Reflector, the only thing I can think of is subclassing HTMLTextWriter own.
"Binary is not the first element in an enumeration of styles," ~HtmlTextWriterStyle.BackgroundColor , is what it uses for any style whose name it does not recognize, and therefore does not bother checking if the value needs "url ()" when he is actually discharged.
HtmlTextWriterEx not the biggest name, but anything. Depending on what you are doing, you may (?) Do something similar in your subclass of System.Web.UI.Page :
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer) { return new HtmlTextWriterEx(writer); }
And here is the class:
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); } }
source share