我想打印预览一个aspx页面,我用的方法是引用IE浏览器的打印预览:
<body ms_positioning="GridLayout">
<form id="Form1" method="post" runat="server">
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0> 
</OBJECT> 
.......
<input id=btPrint runat=server type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)> 
......
运行后就是没反应,那位大虾帮我看一下,必以高分相赠,谢谢

解决方案 »

  1.   

    在aspx页面中直接用<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0> 
    </OBJECT> 不行,要这样:
    页面中
    <% =webobject%>
    后台
    webobject="<OBJECT  id=WebBrowser  classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2  height=0  width=0></OBJECT>";
      

  2.   

    protected string webobject;
    还要声明:)
      

  3.   

    <OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" id="wb" name="wb"
    width="0" VIEWASTEXT>
    </OBJECT>
      

  4.   

    simonw(!simon) ,能不能再详细点,都写在什么位置
      

  5.   

    默认IE安全是没有足够权限运行 WebBrowser ActiveX Object
      

  6.   

    你试试下面的,如果不行就是你的IE的安全等级的问题。<html>
    <head>
    <title></title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name=ProgId content=VisualStudio.HTML>
    <meta name=Originator content="Microsoft Visual Studio .NET 7.1">
    <OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0 >
    </OBJECT> 
    <script language=javascript>
    function window.onload(){
        window.document.body.innerHTML="<p>测试</p>"
        window.focus();
        window.document.all.WebBrowser.ExecWB(7,1);
        this.opener = null;
        this.close();
    }
    </script>
    </head>
    <body>
    </body>
    </html>
      

  7.   

    提示元素object不能嵌套在head中
      

  8.   

    点击左下角的错误图标,具体看看什么错误。<OBJECT id="wb" height="0" width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
    <PARAM NAME="ExtentX" VALUE="26">
    <PARAM NAME="ExtentY" VALUE="26">
    <PARAM NAME="ViewMode" VALUE="0">
    <PARAM NAME="Offline" VALUE="0">
    <PARAM NAME="Silent" VALUE="0">
    <PARAM NAME="RegisterAsBrowser" VALUE="0">
    <PARAM NAME="RegisterAsDropTarget" VALUE="1">
    <PARAM NAME="AutoArrange" VALUE="0">
    <PARAM NAME="NoClientEdge" VALUE="0">
    <PARAM NAME="AlignLeft" VALUE="0">
    <PARAM NAME="NoWebView" VALUE="0">
    <PARAM NAME="HideFileNames" VALUE="0">
    <PARAM NAME="SingleClick" VALUE="0">
    <PARAM NAME="SingleSelection" VALUE="0">
    <PARAM NAME="NoFolders" VALUE="0">
    <PARAM NAME="Transparent" VALUE="0">
    <PARAM NAME="ViewID" VALUE="{0057D0E0-3573-11CF-AE69-08002B2E1262}">
    <PARAM NAME="Location" VALUE="res://C:\WINNT\system32\shdoclc.dll/dnserror.htm#http:///">
    </OBJECT>
    <OBJECT id="factory" style="DISPLAY: none" codeBase="ScriptX.cab#Version=6,1,431,2" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814">
    </OBJECT>
    <script language="javascript">
    function print()
    {
    //打印
      wb.execwb(6,1);
      
    }
    function printsetup()
    {
    //打印页面设置
       wb.execwb(8,1);
    }
    function printpreview()
    {
    //打印页面预览
    wb.execwb(7,1);
    }
    function printit()
    {
    if(confirm('确定打印吗?'))

    wb.execwb(6,6);
    }
    }

    function SetPrintSettings() {

    factory.printing.SetMarginMeasure(2); 
    factory.printing.printer = "HP DeskJet 870C";
    factory.printing.paperSize = "A4";
    factory.printing.paperSource = "Manual feed";
    factory.printing.collate = true;
    factory.printing.copies = 2;
    factory.printing.SetPageRange(false, 1, 3); // 要打印的页面 factory.printing.header = "This is MeadCo";
    factory.printing.footer = "Advanced Printing by ScriptX";
    factory.printing.portrait = false;
    factory.printing.leftMargin = 1.0;      //页边距
    factory.printing.topMargin = 1.0;
    factory.printing.rightMargin = 1.0;
    factory.printing.bottomMargin = 1.0;
    } function Printframe(frame) {
    factory.printing.Print(true, frame) // 打印框架
    }
    </script>
    <input onclick="print()" type="button" value="打印页面"> <input onclick="printit()" type="button" value="直接打印">
    <input onclick="printsetup()" type="button" value="页面设置"> <input onclick="SetPrintSettings()" type="button" value="推荐设置">
    <input onclick="printpreview()" type="button" value="打印预览">
      

  9.   

    在print.aspx页面中直接用<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0> 
    </OBJECT> 不行,要替换成这样:
    例如
    页面中 print.aspx
    <% =webobject%>
    后台 print.aspx.cs
    protected string webobject="<OBJECT  id=WebBrowser  classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2  height=0  width=0></OBJECT>";我一前就是这么解决的.