Messagebox in asp.net

你说的曾经没有我的故事 提交于 2019-12-08 14:09:18

问题


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.


回答1:


 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");



回答2:


try:

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



回答3:


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




回答4:


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 %>



回答5:


Easier:

MsgBox("Text")

Or:

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

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



来源:https://stackoverflow.com/questions/8338630/messagebox-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!