2011-03-06 73 views
-1

我该如何在asp.net页面中显示一个messageBox? (我用C#编写) 我需要写whice行吗?如何在asp.net中显示messageBox/alert?

+2

哇,至少[78个类似的问题(http://stackoverflow.com/search?q = asp.net +消息框)。 – 2011-03-06 15:32:13

回答

2

你可以尝试这样的事情。

protected void Page_Load(object sender, EventArgs e) 
{ 
     Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "test", "<script>alert('hi');</script>"); 
} 
1

在ASP.NET中没有直接控制像WinForms的消息框。 您可以下载ASP.NET工具包并使用ModalPopupExtender,然后创建您自己的MessageBox。

或..您可以在您的ASP.NET页面中使用JavaScript来显示使用Javascript的警报。

1

必须使用JavaScript执行此操作,方法是使用Page.ClientScript.RegisterStartupScriptRegisterClientScriptBlock来调用客户端的JS方法alert("this is my messagebox");

您还可以使用AJAX控件工具包ModalPopupExtender或JQuery的对话框组件。

HTH。

0

使用JavaScript

Button1.Attributes.Add("onclick","alert('Hello World!!!');"); 
0

写在你选择的事件中:

Interaction.MsgBox("Your Text Goes Here");