2011-12-01 76 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 ...)