2011-03-06 80 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");