Webforms打印对话框未显示第二次 [英] Webforms print dialog not showing the second time

查看:60
本文介绍了Webforms打印对话框未显示第二次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



道歉,因为我不是网络开发人员,但偶尔做一些奇怪的工作,需要我创建一个网页表格或2.我有要求在网页上打印报告,我试图让打印按钮可靠地工作。



我遇到的问题是第二次由于某种原因,我按下打印按钮而不打开打印对话框我无法理解原因。


请查看我的问题的简化版本下面



Hi All,

Apologies as I'm not a web developer but occasionally do the odd job which requires me to create a web form or 2. I have a requirement to print off a report on a webpage and I'm trying to get the print button to work reliably.

The problem I'm having is the second time I'm pressing the print button its not opening a print dialog box for some reason and I can't work out why.

Please see the simplified version of my problem below

protected void PrintAllButton_OnClick(object sender, EventArgs e)
        {
            using (var pdi = new PrintDialog())
            {
                if (pdi.ShowDialog() == DialogResult.OK)
                {
                }
            }
        }





对话框触发正确的第一次和它在使用声明,所以应该正确清理,但我显然缺少一些东西



提前谢谢。



我尝试过的事情:



Google搜索并简化解决方案,以便在上面最简单的方案



The dialog fires correctly the first time and its in a using statement so should be cleaned up correctly but I'm clearly missing something

Thanks in advance.

What I have tried:

Googling and simplifying the solution to the easiest possible scenario above

推荐答案

您显示的代码是在服务器上执行



在Visual Studio中调试代码时,它可能出现,但这只是因为服务器和客户端在该特定实例中是同一台机器。



一旦将代码部署到真实服务器,它就会中断。充其量,您将获得一个异常,告诉您当前进程不是交互式的。在最坏的情况下,对话框将出现在服务器上,没有人会看到它,你的代码将等待有人按下不可见对话框上的按钮。



如果要打印当前的HTML文档,则需要使用客户端上运行的Javascript,并调用 Window.print() [ ^ ]方法。



如果你想打印除HTML以外的东西,那么你将会有让用户下载文件并自行打印。无法从Javascript开始打印外部文件。
The code you've shown is executing on the server.

It might appear to work when you debug your code within Visual Studio, but that's only because the server and the client are the same machine in that specific instance.

As soon as you deploy your code to a real server, it will break. At best, you'll get an exception telling you that the current process is not interactive. At worst, the dialog box will appear on the server, where nobody will ever see it, and your code will hang waiting for someone to press a button on an invisible dialog box.

If you want to print the current HTML document, you'll need to use Javascript running on the client, and call the Window.print()[^] method.

If you want to print something other than HTML, then you're going to have to let the user download the file and print it themselves. There is no way to initiate printing an external file from Javascript.


这篇关于Webforms打印对话框未显示第二次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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