EnzoZow
EnzoZow

Reputation: 63

Using MessageBox C# - Throws Error

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.

Upvotes: 0

Views: 435

Answers (2)

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4211

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

Upvotes: 2

M. Adeel Khalid
M. Adeel Khalid

Reputation: 1796

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.

Upvotes: 5

Related Questions