2011-12-01 74 views
0

我需要一個簡單的消息框在asp.net中,我嘗試了下面的代碼。在asp.net中的消息框

Me.Page.ClientScript.RegisterStartupScript(Me.GetType(), "clientScript","<script>javascript:alert('Guest already associated with 
another event');</script>") 

但我沒有運氣。其實我有一個下拉列表,這是在更新面板中它應該通過MessageBox拋出一個錯誤消息。我不知道爲什麼JavaScript不工作。有什麼其他的方式可以在MessageBox中顯示簡單的錯誤信息。

+0

哪裏這個代碼調用的按鈕數? Page_Load中? –

+0

你什麼時候想看到該警報?點擊按鈕或選擇下拉菜單中的項目 –

+0

看起來類似於http://stackoverflow.com/questions/1782847/simple-asp-net-messagebox – coolcake

回答

6
static public void DisplayMessage(Control page, string msg) 
{ 
    string myScript = String.Format("alert('{0}');", msg); 

    ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, true); 
} 



DisplayMessage(this, "Guest already associated with another event"); 
+1

我找到的最好的方法直到日期! – codegasm

0

嘗試:

private void MessageboxAnzeigen(string content){ 
    string Script 
    = "<script type=\"text/javascript\">alert('" 
    + content 
    + "')</script>"; 
    RegisterClientScriptBlock("WindowOpener", Script); 
} 
0

使用這種簡單的方法

protected string Alert = ""; 
page_load(sender e ...) 
{ 

    Alert ="<script>alert('hi');</script>"; 

} 

,並在你的aspx文件中使用此代碼,以提醒消息

<%= Alert %> 
0

更容易:

MsgBox("Text") 

或者:

MsgBox("Text", 0, "Title") 

0是(0是1,1是2 ...)