0

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.

4

5 Answers 5

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");
Sign up to request clarification or add additional context in comments.

1 Comment

The best method I found till date!
0

try:

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

Comments

0

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

Comments

0

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

Comments

0

Easier:

MsgBox("Text")

Or:

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.