0

I want to use MessageBox in C#

using System.Windows.Forms;

MessageBox.Show("Some text", "Some title",MessageBoxButtons.OK, MessageBoxIcon.Error);

Still I got this error. How to fix it?

The MessageBox does not exist in current context.
2
  • 3
    You are trying to use in asp.net, webforms? it could not be used there. Commented Mar 13, 2017 at 6:42
  • 2
    Possible duplicate of MessageBox in C# showing error Commented Mar 13, 2017 at 6:43

2 Answers 2

5

You can not use MessageBox within asp.net, try using Javascript confirm instead. Here is its usage confirmation yes or no message in asp net or you can use it for some other problems too.

Sign up to request clarification or add additional context in comments.

Comments

2

Asp.net doesn't support MessageBox.. You can use this instead of MessageBox.

ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('" + Your Message here + "');", true);

to use this:

String str = "This is your message.";
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('" + str  + "');", true);

This way:

private void show(string message)
{
    System.Web.UI.Page page = this.Page;
    ScriptManager.RegisterStartupScript(page, page.GetType(), "popup", "alert('" + message + "');", true);
}

To use this:

 show("this is your message");

9 Comments

I used this line. but "this" syntax throws error. What word should I replace to it?
Throws the same error. I put the codes at may method, XXXXX.aspx.cs. Is there any conflict?
no problem about that.. what error? do you have this above? using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
Keyword 'this' is not valid in a static property, static method, or static field initializer
You are using static procedure i think. You can try it in form_load first to test if working.
|

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.