Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MessageBox in C# showing error

Tags:

c#

messagebox

I was attempting to add MessageBox.Show(Message); and it was not found in my C# .net web application (button click method and also in Page_Load).An error showing like

'The name 'MessageBox' does not exist in the current context'

Do I need to add any assembly reference for this? (I am using .net framework 4). Is there any alternative method for this?

like image 348
Sudha Avatar asked Apr 01 '13 10:04

Sudha


People also ask

What is MessageBox?

A message box is a special dialog box used to display a piece of information to the user. As opposed to a regular form, the user cannot type anything in the dialog box. To support message boxes, the Visual Basic language provides a function named MsgBox.

How do I view MessageBox?

To display a message box, call the static method MessageBox. Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.

Which is the default MessageBox button?

The second button on the message box is the default button.

What is MessageBox class explain MessageBox () in detail?

A message box is a prefabricated modal dialog box that displays a text message to a user. You show a message box by calling the static Show method of the MessageBox class. The text message that is displayed is the string argument that you pass to Show.


2 Answers

The key words in your description are

web application

This functionality is only available in client (WinForms, WPF) based applications, not ASP.NET. To do this in a web app you will need to use Javascript, as illustrated in this previous Stack Overflow question.

like image 86
slugster Avatar answered Nov 15 '22 14:11

slugster


Use This:

System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('" + Message + "')", true);

Hope This help.

like image 44
Sharique Ansari Avatar answered Nov 15 '22 14:11

Sharique Ansari