MessageBox in C # showing error

I tried to add MessageBox.Show(Message); and was not found in my C # .net web application (button click method, as well as in Page_Load ). Error showing how

'The name MessageBox does not exist in the current context

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

+7
source share
4 answers

Use this:

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

Hope this help.

+2
source

The keywords in your description are

web application

This function is available only in client (WinForms, WPF) applications, and not in ASP.NET. For this, in a web application you will need to use Javascript, as shown in the previous stack overflow question .

+5
source

The MessageBox class in the System.Windows.Forms can be used from Windows Forms and not from ASP.NET Web Forms.

+2
source

System.Windows.MessageBox used in WPF applications and System.Windows.Forms.MessageBox used in Windows Form applications , but your project is WebApplication , so you donโ€™t have access to any of them.

+2
source

All Articles