ASP.NET中ReportView与IE11兼容性解决方法


ASP.NET #reportview2014-04-05 11:11

1.查询时报表出错:

在报表模板中加入了“横线”控件所致,删除即正常了。


2.报表控件上不显示打印按钮:

原因:

由于ReportView的打印功能是依赖于一个RSClientPrint的ActiveX控件的,而ActiveX只能运行在IE浏览器上。


微软改变了IE11的User-Agent 


IE11:User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko


IE10:User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)


致使ReportView控件服务器端判断当前的IE11浏览器为非IE浏览器,没有发送创建“打印”按钮的相关js代码,所以没有显示打印按钮。


解决:

在网站根目录下创建App_Browsers目录加入browser文件。

<browsers>
    <browser id="IE11" parentID="Mozilla">
        <identification>
            <userAgent match="Trident\/7.0; rv:(?'version'(?'major'\d+)(\.(?'minor'\d+)?)(?'letters'\w*))(?'extra'[^)]*)" />
            <userAgent nonMatch="IEMobile" />
        </identification>
        <capture>
            <userAgent match="Trident/(?'layoutVersion'\d+)" />
        </capture>
        <capabilities>
            <capability name="browser"              value="IE" />
            <capability name="layoutEngine"         value="Trident" />
            <capability name="layoutEngineVersion"  value="${layoutVersion}" />
            <capability name="extra"                value="${extra}" />
            <capability name="isColor"              value="true" />
            <capability name="letters"              value="${letters}" />
            <capability name="majorversion"         value="${major}" />
            <capability name="minorversion"         value="${minor}" />
            <capability name="screenBitDepth"       value="8" />
            <capability name="type"                 value="IE${major}" />
            <capability name="version"              value="${version}" />
        </capabilities>
    </browser>

    <!-- Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11,0) like Gecko http://yige.org/-->
    <browser id="IE110" parentID="IE11">
        <identification>
            <capability name="majorversion" match="11" />
        </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>
</browsers>
3.打印按钮显示出来后,打印不了:


  原因:


  由于ReportView在页面生成时并不直接加载RSClientPrint控件,而是在点击打印按钮时由JS动态添加OBJECT元素来加载RSClientPrint控件,问题就在这里。


原来IE11在添加OBJECT元素后并没有从服务器端加载RSClientPrint控件,所以打印无效。


  解决:


  在aspx页面中直接加入OBJECT元素。
<%if(Request.Browser.Type.IndexOf("IE11")>-1){%>
    <object id="ReportViewer1_PrintObj" classid="CLSID:5554DCB0-700B-498D-9B58-4E40E5814405" codebase="http://yige.org/Reserved.ReportViewerWebControl.axd?
Culture=2052&CultureOverrides=True&UICulture=2052&UICultureOverrides=True&ReportStack=1&
ControlID=57e8d903ef7748f7a0c02a1c6bdb851d&Mode=true&OpType=PrintCab&Arch=X86#Version=2009,100,1750,0" style="display: none;" 
VIEWASTEXT=""></object>
<%} %>


    注意:object 的id="ReportViewerID"_PrintObj,codebase=路径,可能由于控件版本的不同而和本例不同。


相关文章

粤ICP备11097351号-1