为什么ASP.Net添加" BORDER"属性到ASP:图像 [英] Why does ASP.Net add a "border" attribute to asp:Image

查看:222
本文介绍了为什么ASP.Net添加" BORDER"属性到ASP:图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个asp.net图片标签:

So I have an asp.net image tag:

<asp:Image runat="server" ImageUrl="~/Images/img.jpg" width="350px" height="250px" AlternateText="My Image" />

但它的输出是:

<img src="Images/img.jpg" height="250" width="350" border="0" />

...的XHTML验证估计,边框元素不应该存在...但它ASP.Net那就是把它。

...the XHTML validator reckons that the "border" element shouldn't be there...but it's ASP.Net that's adding it.

我敢肯定,这个问题已经被问过很多次,但为什么asp.net认为它需要添加它,特别是因为它是无效的?

I'm sure this question has been asked many times before, but why does asp.net think it needs to add it, especially because it's invalid??

这怎么可能避免,以免它验证?

How can this be avoided so that it does validate?

推荐答案

我将与丹同意,img标签将与风格,而不是边界=0,但有相当的研究很少,我没有,边框呈现{:无边框}无论是在外部样式表或同一页面,神奇的是如何发生的超出了我的研究范围上,当你应用样式与IMG控制= 0时消失。不过,我已经注意到,验证仍然得到的加价BORDER = 0,这意味着asp.net呈现不同,这取决于浏览器(或浏览器代理我认为)的类型,要解决这个我不得不强迫ASP来始终呈现'干净'code,如下所示

I would agree with Dan, the img tag will render with a style instead of border="0", but with the rather little research i did, the border=0 only disappears when you apply a style to the control with img {border: none} either in an external stylesheet or on the same page, how the magic happens was beyond the scope of my research. However, i have noticed that the validator still gets a border=0 in the markup, which means that asp.net renders differently depending on the type of browser (or browser agent i think), and to solve this i had to force asp to always render 'clean' code, as illustrated here

http://blog.hmobius.com/post/2010/03/03/ASPNET-Part-9-Rendering-Cleaner-HTML.aspx

所以在我的情况,我加入到web.config文件

so in my case, i added to the web.config file

<pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">

也还有一点,我使用的是HTML5文档类型,所以一定要确保你的网页的DOCTYPE是没有问题的。

also another point, i am using the html5 doctype, so make sure that the doctype of your page is not the problem.

和我的网页验证。

这篇关于为什么ASP.Net添加&QUOT; BORDER&QUOT;属性到ASP:图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆