c# - MessageBox 自动继续,无需按下按钮

标签 c# messagebox dialogresult

我有一个带有两个按钮和一个文本的消息框。 这是相关代码:

var result = MessageBox.Show("just a text","just a title",MessageBoxButtons.OKCancel,System.Windows.Forms.MessageBoxIcon.Warning,System.Windows.Forms.MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.ServiceNotification | System.Windows.Forms.MessageBoxOptions.RightAlign);
if (result == DialogResult.OK)
{
    ... code ...
}

我的问题是程序自动在“if”中输入代码,弹出消息框甚至没有显示。 即使在我调试它时,我也会看到代码转到“if”行,结果是 DialogResult.OK。

我正在使用网络表单和 ASP.Net。

MessageBox 的命名空间是“System.Windows.Forms”。

我尝试清除缓存甚至 iisreset。

还有什么可以帮助我?

提前谢谢你。

最佳答案

I am using web forms and ASP.Net.

the namespace for the MessageBox is "System.Windows.Forms".

不要那样做。 ASP.NET 站点在服务器上运行,所以没有人可以单击 MessageBox,即使它会在服务器上弹出。

如果您想向用户显示弹出窗口,则必须使用 Javascript。参见 How to make a simple yes/no popup in ASP.NET that return the result back to my c#? .

关于c# - MessageBox 自动继续,无需按下按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30027484/

相关文章:

c# - 序列化不可序列化的自定义外部类

c# - 如何获取 .m4v 格式电影的运行时间?

delphi - 如何抑制 Delphi DataSnap 错误消息对话框?

c# - 消息框关闭表单不正常

c++ - 获取 PrintDialog 的结果

c# - 如何加速无尽跑酷

c# - 如何在 C# 中获取列表中新添加项的索引?

c# - wpf中的DialogResult问题

c# - 创建无模式消息框

r - 在 R 中设计对话框