2
A
回答
1
RegisterClientScriptBlock可以提供幫助嗎?
2
添加WebMsgBox類以下到您的項目。那麼無論你需要從代碼彈出一個消息框,只是這樣做:
WebMsgBox.Show("How to show alert message!");
的WebMsgBox類:
using System;
using System.Text;
using System.Collections;
using System.Web;
using System.Web.UI;
public class WebMsgBox
{
protected static Hashtable handlerPages = new Hashtable();
private WebMsgBox() { }
public static void Show(string Message)
{
if (!(handlerPages.Contains(HttpContext.Current.Handler)))
{
Page currentPage = (Page)HttpContext.Current.Handler;
if (!((currentPage == null)))
{
Queue messageQueue = new Queue();
messageQueue.Enqueue(Message);
handlerPages.Add(HttpContext.Current.Handler, messageQueue);
currentPage.Unload += new EventHandler(CurrentPageUnload);
}
}
else
{
Queue queue = ((Queue)(handlerPages[HttpContext.Current.Handler]));
queue.Enqueue(Message);
}
}
private static void CurrentPageUnload(object sender, EventArgs e)
{
Queue queue = ((Queue)(handlerPages[HttpContext.Current.Handler]));
if (queue != null)
{
StringBuilder builder = new StringBuilder();
int iMsgCount = queue.Count;
builder.Append("<script language='javascript'>");
string sMsg;
while ((iMsgCount > 0))
{
iMsgCount = iMsgCount - 1;
sMsg = System.Convert.ToString(queue.Dequeue());
sMsg = sMsg.Replace("\"", "'");
builder.Append("alert(\"" + sMsg + "\");");
}
builder.Append("</script>");
handlerPages.Remove(HttpContext.Current.Handler);
HttpContext.Current.Response.Write(builder.ToString());
}
}
}
0
可以使用ClientScript從服務器端執行JavaScript代碼。 爲了提供警報,您必須在保存值後編寫ClientScript.RegisterStartupScript/ClientScript.RegisterClientScriptBlock。
如果您的按鈕是在更新面板,那麼你必須使用ScriptManager.RegisterClientScriptBlock,而不是ClientScript。
0
相關問題
- 1. 從Windows服務中顯示消息框
- 2. 如何顯示服務器端的彈出消息
- 3. jqgrid如何顯示服務器端消息
- 4. 如何顯示服務器端驗證錯誤消息?
- 5. ASP.net,如何從服務器端代碼顯示一個警告框?
- 6. 在asp.net服務器端的消息框
- 7. 顯示消息框的Web服務
- 8. socket.io從服務器端發起消息
- 9. 消息,從服務器的客戶端
- 10. 客戶端向服務器發送消息。但服務器不顯示它
- 11. Firebase雲消息傳遞和C#服務器端代碼
- 12. 在ValidationMessageFor Block中顯示服務器端驗證消息
- 13. 服務器端(後面的代碼)是否確認ASP.Net中的消息框C#
- 14. 當我從服務器端顯示Telerik radAlert時,如何停止代碼執行
- 15. 從服務器端代碼獲取會話信息到客戶端代碼
- 16. 無法在asp.net中的dev服務器上顯示消息框
- 17. 如何將消息從服務器發送到客戶端
- 18. Java ActiveMQ:如何發送消息從客戶端到服務器
- 19. 如何發送消息從服務器到客戶端流星?
- 20. 如何在asp.net中顯示來自服務器端的通知或消息?
- 21. ASP.NET MVC:如何在服務器端處理後顯示成功確認消息
- 22. 如何顯示在彈出的Struts2服務器端驗證錯誤消息?
- 23. 如何從服務器端C#代碼觸發客戶端JavaScript?
- 24. 如何從服務器端代碼獲取客戶端timeZoneOffset
- 25. 如何從客戶端隱藏服務器端代碼?
- 26. C#,從業務邏輯中分離消息顯示代碼
- 27. 從服務器端註冊javascript代碼
- 28. 如何在JSF中顯示服務器生成的消息?
- 29. 如何顯示Apache FTP服務器消息
- 30. 從服務器端驗證顯示ASP.Net MVC中的成功驗證消息
這可以用於除了jQuery UI對話框。見http://jqueryui.com/demos/dialog/ –