如何在c#网页中 使用 MessageBox 的问题

我用C#2005写了一个asp.net2.0的网页, 其中我要用到 MessageBox,代码如下:
...
...
using System.Windows.Forms;
...
...
protected void Button1_Click(object sender, EventArgs e)
{
string message1 = "您目前暂无待办事项!!";
string caption = "系统提醒您";

MessageBox.Show(message1, caption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}

当我在别的电脑上浏览这个网页时,当我 单击 Button1时, 这个 MessageBox 它没有显示到用户的界面上,而是在 我的IIS服务器上 show 出来
C# asp.net

protected void Button1_Click(object sender, EventArgs e)
{

string str ;
str =" <script language=javascript>\n";

str =str + " if(confirm('你是否要继续'))\n";
str =str + " { location.href='www.163.com'; \n}\n"; //我可不可以把这里的语句改成C#的语句,或调用我的C#函数,而不是跳转页面
str =str + " else \n ";
str =str + " { alert(' 按了取消);}"; // 还有这里的语句, 可不可以 写 比方说 Lable1.Text="你按取消了";
str =str + " </script>"; System.Web.HttpContext.Current.Response.Write(str );

}

现在

我以前也遇到过这样的情况。
你不能在网页上使用MessageBox这个东西。
原因:因为,每个电脑的内核不同。所集成的系统函数也不一样。
而你调用的MessageBox,是你机器上的系统函数。在别人机器上可能没有的。
所以在别人的机器上显示不了,在你机器上能显示。

我一般用javascript中的alert来弹出提示框。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-03-20
方法1:
<script type="text/javascript" >
function Message(){
alert("Your message !");
}
</script>
把这段javascript代码放到你的asp页面上,在你的按钮上
<input type="button" OnClick="Message()">Test</input>
意思就是在你点击按钮时弹出信息。
类似的用vbscript也可以。
方法2:
用asp隐式对象,response重定向到客户端
Response.Write("<script>alert('美女,你没有这个权限啊!');</script>");
第2个回答  2007-03-20
首先引用using System.Web;定义类Msg
public class Msg
{
#region 在客户端返回用户操作信息
/// <summary>
/// 在客户端返回用户操作信息,可再加入JS脚本在客户端执行.
/// </summary>
/// <param name="Info">要返回的提示信息(信息以弹出对话框形式显示)</param>
/// <param name="Action">需要再执行的JS脚本操作,可以是重定向到其它页面等...</param>
public static void RetInfo(string Info,string Action)
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('"+Info+"');"+Action+";</script>");
}
public static void RetInfo(string Info)
{
System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('"+Info+"');</script>");
}
#endregion
}
调用方法:
Msg.RetInfo("用户名不能为空!"); 弹出Message提示框
Msg.RetInfo("修改失败!","location='Manage.aspx'"); 弹出消息提示框,点确定之后返回Manage.aspx页面

弹出确定,取消对话框
function Msg(){
if (confirm("您只指定了 会办单位 但没有指定 核准人 ,是否继续?")==true)
{
//事件一;
return true;
}
else
{
//事件二;
return false;
}
}
第3个回答  2007-03-20
在客户端弹消息框需要用js,你这个方法肯定是在服务器上弹的

---------------------------

如果想实现用户的选择做不同的动作,可以换个思路,用一个确认页面来代替弹出框,让用户跳转到这个页面上来,上面放多少个操作按钮都行,比较灵活
第4个回答  2007-03-20
直接
Response.Write("<script>window.confirm('"+message+"')</script>")
就可以了

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网