How to show MessageBox on asp.net?

if I need to show MessageBox on my ASP.NET WebForm how to do it?

I'm trying: Messagebox.show("dd");

But it does not work.

+6
source share
8 answers

MessageBox does not exist in ASP.NET. If you need functionality in the browser, for example, displaying a message box, you need to select javascript . ASP.NET provides you with a javascript input tool that is rendered and executed when the html sent to the browser is loaded and displayed. You can use the following code in Page_Load, for example:

 Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Check to see if the startup script is already registered. if (!cs.IsStartupScriptRegistered(cstype, "PopupScript")) { String cstext = "alert('Hello World');"; cs.RegisterStartupScript(cstype, "PopupScript", cstext, true); } 

This sample is extracted from MSDN .

+10
source share

Messagebox is for windows only. You must use javascript

 Alert('dd'); 
+4
source share

There is a fairly concise and simple way:

 Response.Write("<script>alert('Your text');</script>"); 
+3
source share

One option is to use Javascript.

Here is a short link to get you started.

Javascript warning messages

+1
source share

The message box is available by default for a Windows form application. If you want to use the message box resource, you will need to use 'using system.windows.forms' to enable the message box for web form mode.

0
source share

It is true that Messagebox.show("dd"); not part of using System.Web; ,

I felt the same situation for most of the time. If you want to do this, follow these steps.

  • Right click on the project in the solution explorer
  • go to add a link, then select the .NET tab

  • And select System.windows.forms (press 's' to quickly find)

u can get a namespace, now you can use Messagebox.show("dd");

But I recommend going with a javascript warning for this.

0
source share

You can simply write, but you must use JavaScript independently.

 Page.ClientScript.RegisterStartupScript(Page.GetType(), "Message Box", "<script language = 'javascript'>alert('dd')</script>"); 
0
source share

You can use MessageBox if you want, but using alert (from JavaScript) is recommended instead.

If you want to use it, you should write:

 System.Windows.Forms.MessageBox.Show("Test"); 

Please note that you must specify a namespace.

-2
source share

All Articles