ASP.Net不正确的背景图片呈现的风格

编程入门 行业动态 更新时间:2024-10-25 14:32:01
本文介绍了ASP.Net不正确的背景图片呈现的风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用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

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不正确的背景图片呈现的风格

本文发布于:2023-11-12 09:39:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不正确   背景图片   风格   ASP   Net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!