现在的位置: 首页 > 综合 > 正文

ASP.NET中弹出MessageBox的方法

2012年10月01日 ⁄ 综合 ⁄ 共 498字 ⁄ 字号 评论关闭

第一种,使用JavaScript实现:在aspx文件中拖入一个button按钮,双击按钮,编辑该按钮的事件如下:

1protected void msgButton_Click(object sender, EventArgs e)
2    {
3        Page.RegisterStartupScript("alert""<script language='Javascript'> alert('弹出一个消息框!')</script>");
4    }
 

第二种:利用C#直接实现:

右击Solution Explore中的站点,点击“添加引用”将System.Windows.Forms添加进来

然后在aspx文件中拖入一个button,双击进入对应的.cs文件的编辑,在头部加入如下的引用:

using System.Windows.Forms;

然后编辑对应的ButtonClick事件

protected void Button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("弹出MessageBox对话框");
    }

 

抱歉!评论已关闭.