Microsoft ReportViewer 控件(Web)&显示错误消息

发布于 2024-11-30 00:37:42 字数 588 浏览 1 评论 0原文

我的网页上有一个 Microsoft ReportViewer 控件。然而,如果有人为其中一个参数输入了无效的输入,那么它会在报告应该去的地方显示一条相当不友好的错误消息。例如:为报表参数“pToDate”提供的值对其类型无效。 (rsReportParameterTypeMismatch)

控件提示用户输入“To Date”信息,“pToDate”是参数的内部名称。用户不会知道这一点,他们也不可能对“rsReportParameterTypeMismatch”做出良好反应(这意味着什么!?[同时像用户一样思考])

因为我无法在 ReportViewer 控件中找到放置任何错误或自定义的位置消息,我的解决方案是创建一个标签,在其中放置更友好的错误消息。只要显示友好的错误消息,此操作就有效。

我的问题是,一旦用户纠正了错误并单击“查看报告”,就会显示报告,但错误消息仍然可见。我已将标签文本设置为 string.Empty,并将标签设置为 Visible = false。我在不同的地方尝试过这一点,确保代码被命中,但无济于事。

那么,有什么方法可以使用 ReportViewer 控件让自定义消息出现和消失吗?

I have a Microsoft ReportViewer control on my web page. However, if someone types in an invalid input for one of the parameters then it displays a rather unfriendly error message where the report should go. For example: The value provided for the report parameter 'pToDate' is not valid for its type. (rsReportParameterTypeMismatch)

The control prompts the user for the information with "To Date" and "pToDate" is the internal name of the parameter. The users won't know this, nor will they likely react well to "rsReportParameterTypeMismatch" (what ever that means!? [while thinking like a user])

As I couldn't find somewhere in the ReportViewer control to put any error or custom message, my solution was to create a label in which to put a more friendly error message. This works insofar as the friendly error message is displayed.

My problem is that once the user has corrected their mistake and clicks "View Report" the report is displayed but the error message is still visible. I've set the label text to string.Empty, I've set the label to Visible = false. I've tried this in various places, ensured the code is hit, but to no avail.

So, is there any way to get custom messages to appear and disappear with a ReportViewer control?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情 2024-12-07 00:37:42

好吧 - 我有一些可以工作的东西

以前我有这个:

<asp:Label runat="server" ID="ReportErrorMessage" Visible="false" CssClass="report-error-message">
</asp:Label>

我在后面的代码中更新了这样的:

ReportErrorMessage.Text = GetErrorMessage(reportException);
ReportErrorMessage.Visible = true;

然后像这样删除:

ReportErrorMessage.Visible = false;
ReportErrorMessage.Text = string.Empty;

后一部分不起作用。

我最终意识到 ReportViewer 控件正在使用部分渲染,因此实际上根本没有更改标签(考虑到这一点,我仍然不太清楚初始显示实际上是如何工作的,但无论如何......

)是将标签包装在更新面板中,如下所示:

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:Label runat="server" ID="ReportErrorMessage" Visible="false" CssClass="report-error-message">
        </asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

更新

我还在我的博客上添加了完整的解释:Microsoft Report 的友好错误消息查看器

Okay - I've got something that works

Previous I had this:

<asp:Label runat="server" ID="ReportErrorMessage" Visible="false" CssClass="report-error-message">
</asp:Label>

which I was updating in the code behind like this:

ReportErrorMessage.Text = GetErrorMessage(reportException);
ReportErrorMessage.Visible = true;

and then removing like this:

ReportErrorMessage.Visible = false;
ReportErrorMessage.Text = string.Empty;

The latter part didn't work.

I eventually realised that the ReportViewer control is using partial rendering and so wasn't actually changing the label at all (and consdering that, I've still not quite figured out how the initial display actually worked, but anyway...)

The solution was to wrap the label in an update panel like this:

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:Label runat="server" ID="ReportErrorMessage" Visible="false" CssClass="report-error-message">
        </asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

UPDATE

I've also added a full explanation onto my blog: Friendly Error Messages with Microsoft Report Viewer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文