消息框不起作用

发布于 2024-08-12 18:54:09 字数 339 浏览 4 评论 0原文

我有一个例外,我需要一个消息框,

我的消息框可以在本地主机上工作,但不能在服务器上工作,

catch (Exception)
        {

            MessageBox.Show("Machine Cannot Be Deleted", "Delete from other Places first", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

我怎样才能完成这项工作...谢谢

,有另一种方法可以做到这一点...请帮助...我知道这是一个小问题,但必须完成......

I have an exception where i need to sheo a messagebox

my messagebox works on localhost but not on the server

catch (Exception)
        {

            MessageBox.Show("Machine Cannot Be Deleted", "Delete from other Places first", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

how can i make this work... thanks

is there another way to do this.... please help.. i know this is a small problem but it needs to be done...

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

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

发布评论

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

评论(2

伴随着你 2024-08-19 18:54:09

您不能在 ASP.NET 中使用 Windows 窗体 MessageBox,因为它在服务器端运行,这对于客户端来说毫无用处。

考虑使用 Javascript 警报或其他类型的验证错误。 (也许有一个包含错误消息的隐藏控件,并在 catch 块中切换其可见性或使用 Response.Write 来发出 Javascript 警报)。

像这样的东西(未经测试):

Response.Write("<script language='javascript'>window.alert('Machine Cannot Be Deleted, delete from other places first.');</script>");

You can't use a Windows Form MessageBox in ASP.NET since it runs on the server side, making it useless for the client.

Look into using a Javascript alert or some other type of validation error. (Maybe have a hidden control with your error message and toggle its Visibility in the catch block or use Response.Write for a Javascript alert).

Something like this (untested):

Response.Write("<script language='javascript'>window.alert('Machine Cannot Be Deleted, delete from other places first.');</script>");
箹锭⒈辈孓 2024-08-19 18:54:09

您必须使用命名空间 System.Windows.Forms 然后您可以使用消息框属性,

例如

   using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

**using System.Windows.Forms;**

    public partial class _Default : System.Web.UI.Page 
   {
      protected void Page_Load(object sender, EventArgs e)
       {
          MessageBox.Show("Machine Cannot Be Deleted", "Delete from other Places                   
          first", MessageBoxButtons.OK, MessageBoxIcon.Error);

       }    
    }

在其他替代方案中(除了 Brandon 先生提出的方案之外)

a) 使用 javascript

,例如

Response.Write("<script>alert('Machine Cannot Be Deleted')</script>");

b) 制作一个像消息框一样工作的自定义函数,

例如

protected void Page_Load(object sender, EventArgs e)
    {
        MyCustomMessageBox("Machine Cannot Be Deleted");
    }

    private void MyCustomMessageBox(string msg)
    {
        Label lbl = new Label();
        lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
        Page.Controls.Add(lbl);
    }

希望这有帮助

You have to use the namespace System.Windows.Forms and then you can use Message box property

e.g.

   using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

**using System.Windows.Forms;**

    public partial class _Default : System.Web.UI.Page 
   {
      protected void Page_Load(object sender, EventArgs e)
       {
          MessageBox.Show("Machine Cannot Be Deleted", "Delete from other Places                   
          first", MessageBoxButtons.OK, MessageBoxIcon.Error);

       }    
    }

Among the other alternatives (apart from the one Mr.Brandon has proposed)

a) Use javascript

e.g.

Response.Write("<script>alert('Machine Cannot Be Deleted')</script>");

b) Make a custom function that will work like a message box

e.g.

protected void Page_Load(object sender, EventArgs e)
    {
        MyCustomMessageBox("Machine Cannot Be Deleted");
    }

    private void MyCustomMessageBox(string msg)
    {
        Label lbl = new Label();
        lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
        Page.Controls.Add(lbl);
    }

Hope this helps

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