如何在ASP.NET Web应用程序显示Windows.Form.MessageBox? [英] How to display Windows.Form.MessageBox in ASP.NET web application?

查看:126
本文介绍了如何在ASP.NET Web应用程序显示Windows.Form.MessageBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MessageBox显示我的验证错误消息。我有四个文本框和一个按钮控制。当我按一下按钮控制,在MessageBox显示没有文字文本框。我几乎做到了这一点,但问题是当我点击按钮后,消息框打开为最小化窗口。因此很难为最终用户来实现。我想显示在MessageBox给用户时,点击按钮。

I want to display my validation error messages in the MessageBox. I have Four TextBoxes and One Button control. When I click the Button Control, the TextBoxes without the text to be shown in the MessageBox. I have almost done this, but the problem is When I click the Button, the MessageBox is opened as a minimized window. So it is difficult for the end user to realize. I want to display the MessageBox to the user when button clicks.

下面是我的code,在按钮点击事件

Here is my code, In the Button Click Event

ErrorMsg="";

if (TextBox1.Text == "")
{
    ErrorMsg += "Name is required!";
    ErrorMsg += "\n";
}
if (TextBox2.Text == "")
{
    ErrorMsg += "Address is required!";
    ErrorMsg += "\n";
}
if (TextBox3.Text == "")
{
    ErrorMsg += "Phone No. is required!";
    ErrorMsg += "\n";
}
if (TextBox4.Text == "")
{
    ErrorMsg += "City is required!";
    ErrorMsg += "\n";
}
if (ErrorMsg.Length == 0)
{
     //Some Code
}
else
{
    MessageBox.Show(ErrorMsg, "Existing Address", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

在此先感谢...

Thanks in advance...

推荐答案

您不能在ASP.NET应用程序中使用Windows消息框。它只是没有任何意义。一个ASP.NET吐HTML / JavaScript的/ CSS所以这是你应该用什么来告知出事了用户。因此,例如在ASP.NET应用程序,你可以使用<$c$c>RegisterStartupScript方法JavaScript插入时,页面加载将执行并使用警报页功能:

You cannot use the Windows MessageBox in an ASP.NET application. It just doesn't make sense. An ASP.NET spits HTML/javascript/CSS so that's what you should be using to inform the user that something went wrong. So for example in an ASP.NET application you could use the RegisterStartupScript method to inject javascript into the page which will execute when the page is loaded and use the alert function:

ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('oops');", true);

其它更传统的技术在ASP.NET应用程序中执行验证涉及到使用的验证控件的。

这篇关于如何在ASP.NET Web应用程序显示Windows.Form.MessageBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆