您必须使用命名空间 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);
}
}
在其他替代方案中(除了布兰登先生提出的那个)
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);
}
希望这可以帮助