当应用程序未在用户交互模式下运行时显示模式对话框或窗体

本文关键字:模式 显示 运行时 对话框 窗体 用户 交互 应用程序 | 更新日期: 2023-09-27 18:36:42

大家好,当我的网站在尝试显示打印预览对话框时,当我的网站处于活动状态时,我收到此错误

PrintPreviewDialog ppdlg = new PrintPreviewDialog();
ppdlg.ShowDialog();

如何解决此错误

完全错误

Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.

当应用程序未在用户交互模式下运行时显示模式对话框或窗体

在 asp.Net 中,不能使用 PrintPreviewDialog 类,因为它是 Windows 窗体的一部分。asp.net 代码在服务器端运行。

如果要弹出带有 asp.net 的打印对话框,则必须在客户端进行操作。

这可以通过自定义打印css和一些javascript的组合来实现。这里可能是一个很好的起点: http://www.javascriptkit.com/dhtmltutors/cssmedia.shtml