Asp.net服务器控件在IE10下的不兼容问题

时间:2023-03-08 20:19:21

Asp.net服务器控件在IE10下的不兼容问题

时间:2013-05-16 09:07点击:

89 次 【

相信很多使用IE10的童鞋们已经发现了这个问题,以下是本人在IE10标准模式下发生的问题,声明:IE10不只有一个版本

1.服务器控件属性丢失,在aspx页面定义的TextBox:

  <asp:TextBox ID="txt" runat="server" Width="200" />

  在IE10标准模式下浏览发现宽度不对,遂打开源代码发现成这样了:

  <input name="txt" type="text" id="txt" /> width属性没了

2.偶尔发现页面报错__doPostBack找不到

目前就发现以上两点,第一反应就是兼容性问题,查了一些资料,果然是IE10的bug,不禁对微软的产品不满,新的浏览器尽然连自己的服务器控件都存在兼容性问题。

一般用户只需要设置浏览器在兼容模式下运行就可以解决了,但是开发人员怎么去解决这个问题呢?

VS项目里加App_Browsers文件夹,加ie.browser文件,文件内容帖下面的内容:

<browsers>
     <!-- Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4325) -->
     <browser id="IE6Plus" parentID="IE">
         <identification>
             <capability name="majorversion" match="^[6-9]|\d{2,}$" />
         </identification>
 
         <capabilities>
             <capability name="ecmascriptversion"    value="3.0" />
             <capability name="jscriptversion"       value="5.6" />
             <capability name="javascript"           value="true" />
             <capability name="javascriptversion"    value="1.5" />
             <capability name="msdomversion"         value="${majorversion}.${minorversion}" />
             <capability name="w3cdomversion"        value="1.0" />
             <capability name="ExchangeOmaSupported" value="true" />
             <capability name="activexcontrols"      value="true" />
             <capability name="backgroundsounds"     value="true" />
             <capability name="cookies"              value="true" />
             <capability name="frames"               value="true" />
             <capability name="javaapplets"          value="true" />
             <capability name="supportsCallback"     value="true" />
             <capability name="supportsFileUpload"   value="true" />
             <capability name="supportsMultilineTextBoxDisplay" value="true" />
             <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
             <capability name="supportsVCard"        value="true" />
             <capability name="supportsXmlHttp"      value="true" />
             <capability name="tables"               value="true" />
             <capability name="supportsAccessKeyAttribute"    value="true" />
             <capability name="tagwriter"            value="System.Web.UI.HtmlTextWriter" />
             <capability name="vbscript"             value="true" />
         </capabilities>
     </browser>
 
     <!-- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;) -->
     <browser id="IE6to9" parentID="IE6Plus">
         <identification>
             <capability name="majorversion" match="^[6-9]$" />
         </identification>
     </browser>
 
     <!-- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;) -->
     <browser id="IE7" parentID="IE6to9">
         <identification>
             <capability name="majorversion" match="^7$" />
         </identification>
         <capabilities>
             <capability name="jscriptversion" value="5.7" />
         </capabilities>
     </browser>
 
     <!-- Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729) -->
     <browser id="IE8" parentID="IE6to9">
         <identification>
             <capability name="majorversion" match="^8$" />
         </identification>
         <capabilities>
             <capability name="jscriptversion" value="6.0" />
         </capabilities>
     </browser>
 
     <!-- Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729) -->
     <browser id="IE9" parentID="IE6to9">
         <identification>
             <capability name="majorversion" match="^9$" />
         </identification>
         <capabilities>
             <capability name="jscriptversion" value="6.0" />
         </capabilities>
     </browser>
 
     <!-- Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) -->
     <browser id="IE10Plus" parentID="IE6Plus">
         <identification>
             <capability name="majorversion" match="\d{2,}" />
         </identification>
         <capabilities>
             <capability name="jscriptversion" value="6.0" />
         </capabilities>
     </browser>
 
     <gateway id="IEbeta" parentID="IE">
         <identification>
             <capability name="letters" match="^([bB]|ab)" />
         </identification>
 
         <capture>
         </capture>
 
         <capabilities>
             <capability name="beta"    value="true" />
         </capabilities>
     </gateway>
 </browsers>

这是一种基于站点的修复方式,参考微软官方资料:

.NET 4 浏览器更新 NuGet 包 - http://nuget.org/List/Packages/App_BrowsersUpdate

.NET 2.0 浏览器更新 NuGet 包 - http://nuget.org/List/Packages/App_BrowsersUpdate.net20

还有一种是打补丁,能解决服务器上所有站点的兼容性问题

.NET 4 - http://support.microsoft.com/kb/2600088

.NET 2.0 - http://support.microsoft.com/kb/2600100

另外博主在项目里用了大量的devexpress服务器控件,苦不堪言,虽然按照以上方式进行修复,VS自带的控件倒是没出现问题,但是dev控件却一大堆错误,最终还是没有修复,只能让用户使用兼容性模式。