Messagebox in asp.net

2019-06-13 03:06发布

I need a simple messagebox in asp.net, I tried the following code.

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

but I had no luck. Actually I have a dropdownlist which is in a updatepanel it should throw an error message via a MessageBox. I don't know why javascript not working. Is there any other way by which we could show an simple error message in MessageBox.

5条回答
霸刀☆藐视天下
2楼-- · 2019-06-13 03:30

See this user control which will help you MessageBox Usercontrol with ASP.net

查看更多
别忘想泡老子
3楼-- · 2019-06-13 03:37

use this simple way

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

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

}

and in your aspx file use this code to alert a message

<%= Alert %>
查看更多
狗以群分
4楼-- · 2019-06-13 03:39

Easier:

MsgBox("Text")

Or:

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

0 is the number of buttons (0 is 1, 1 is 2...)

查看更多
做个烂人
5楼-- · 2019-06-13 03:41
 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");
查看更多
ゆ 、 Hurt°
6楼-- · 2019-06-13 03:46

try:

private void MessageboxAnzeigen(string content){
  string Script 
  = "<script type=\"text/javascript\">alert('"
  + content
  + "')</script>";
  RegisterClientScriptBlock("WindowOpener", Script);
 }
查看更多
登录 后发表回答