如何从类库中的类内部显示消息框?

发布于 2024-08-23 05:11:30 字数 124 浏览 5 评论 0原文

谁能告诉我如何在 c# 中的类库项目的 .cs 文件中显示警报消息?

我正在类库项目中调用cs文件的方法。每当控件到达方法内的警报消息语句时,警报消息都应显示在网页(aspx)上,并且不应执行警报消息语句的下一条语句。

Can anyone tell me how to show alert message inside the .cs file of class library project in c#?

I am calling a method of cs file in classlibrary project. Whenever the control comes to the alert message statement inside the method, alert message should be shown on the web page(aspx) and the next statement to the alert message statement should not be executed.

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

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

发布评论

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

评论(3

盛夏尉蓝 2024-08-30 05:11:30

请小心不要在类库中放入过多的 UI 代码。听起来你的类库方法应该抛出异常。然后调用代码可以捕获异常并根据需要将其显示给用户。

Be careful about putting too much UI code in your class libraries. It sounds like your class library method should throw an exception. Then the calling code can trap the exception and display it to the user as needed.

蓝海似她心 2024-08-30 05:11:30

在由明确定义的层组成的应用程序中,永远不应该这样做。

这个问题缺乏关于您试图通过这样做来完成什么的细节,但这里有一些可能性和解决方案:

  • 使用警报作为调试的替代品?使用调试器并单步执行代码;根据需要检查变量。
  • 试图捕获抛出的异常的消息?让异常冒泡到 UI 层,您可以在其中捕获它并显示消息。
  • 尝试从数据库或本地化查找表返回字符串?将其作为函数或属性的结果返回,并显示 UI 层的值。

In an application made of well-defined tiers, this should never be done.

There is a lack of detail in the question as to what you're trying to accomplish by doing this, but here are a few possibilities and solutions:

  • Using the alert as a substitute for debugging? Use the debugger and step through your code; inspect the variables as necessary.
  • Trying to capture the message of an exception that's getting thrown? Let the exception bubble up to the UI layer where you can catch it and show the message.
  • Trying to return a string from a database or from a localized lookup table? Return it as the result of a function or property, and show the value from the UI layer.
挽梦忆笙歌 2024-08-30 05:11:30

您的类库方法应该将错误返回给调用者,并且由调用者决定是否应该显示错误。

Your class library method should return the error to the caller, and it's up to the caller whether the error should be shown or not.

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