Q
消息框在C#
2
A
回答
2
簡單地說,ASP.NET中沒有MessageBox類。由於ASP.NET在服務器上執行,它將顯示在服務器上而不是客戶機(如果有的話)。你最好的選擇是使用JavaScript或寫你自己的。
下面是創建自己的MessageBox類的ASP.NET
public static class MessageBox
{
//StringBuilder to hold our client-side script
private static StringBuilder builder;
public static void Show(string message)
{
//initialize our StringBuilder
builder = new StringBuilder();
//format script by replacing characters with JavaScript compliant characters
message = message.Replace("\n", "\\n");
message = message.Replace("\"", "'");
//create our client-side script
builder.Append("<script language=\"");
builder.Append("javascript\"");
builder.Append("type=\"text/javascript\">");
builder.AppendFormat("\t\t");
builder.Append("alert(\"" + message + "\");");
builder.Append(@"</script>");
//retrieve calling page
Page page = HttpContext.Current.Handler as Page;
//add client-side script to end of current response
page.Unload += new EventHandler(page_Unload);
}
private static void page_Unload(object sender, EventArgs e)
{
//write our script to the page at the end of the current response
HttpContext.Current.Response.Write(builder);
}
}
1
有this讀或只是谷歌,並有數以百計的例子
3
在WinForms的使用MessageBox.Show("Your message");
1
在網頁的一個例子,兩種方式來顯示一個消息是使用JavaScript alert
呼叫或AJAX(即ASP.NET AJAX控制工具包)ModalPopupExtender
。前者通常更簡單,更容易,但你不會有太多的控制權或能夠支持適當的交互性。
1
相關問題
- 1. C#消息框錯誤消息
- 2. Asp.NET中的消息框C#
- 3. C#Winforms消息框屬性
- 4. C#文本框消息
- 5. 的Visual C#.NET消息框
- 6. 如何在C#中使用消息框?
- 7. 在C中自動關閉消息框#
- 8. C#特殊消息框(或輸入框)
- 9. 添加消息,彈出消息框,C#noob問題
- 10. WPF8消息框
- 11. 消息框vba
- 12. 消息框,
- 13. 消息框
- 14. C#VS2008從dll中刪除消息框?
- 15. c中沒有按鈕的消息框#
- 16. C#寫消息的文本框
- 17. C#WINForm避免兩個消息框
- 18. C#WPF XAML窗口,消息框中
- 19. C#/ .NET消息框不是模態
- 20. C#消息框,變量用法
- 21. C#消息框顯示兩次
- 22. C#消息框連續多次顯示
- 23. 消息框顯示得太早 - C#
- 24. C#消息框出現兩次
- 25. Linux中C中的消息框
- 26. C#消息框最小化問題
- 27. 消息框忙着在WPF
- 28. 在asp.net中的消息框
- 29. 在C中的保存對話框上顯示消息框#
- 30. 顯示Django消息框架消息
你是什麼意思「我找不到下拉列表中的消息框....」? – Yakimych 2010-08-02 15:59:51
您的意思是一個JavaScript警報? – 2010-08-02 16:00:35