August 22, 2002 - Using the MessageBox Class | WebReference

August 22, 2002 - Using the MessageBox Class

Yehuda Shiran August 22, 2002
Using the MessageBox Class
Tips: August 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

You're probably well acquainted with the alert() method you use so often in client-side JavaScript code. The alert() method is great for debugging scripts the good old-fashioned way--tracing variables by displaying their values along the flow. JScript .NET provides similar capabilities via the System.Window.Forms.MessageBox.Show() method. You pass this method a single argument, a string, and it pops up a window displaying this string and an OK button.

The message box is called modal. A window or a form is modal if it retains the focus until you explicitly close it. It's a common practice to make dialog boxes and messages modal, since you want to make sure the user reads the message before he or she continues working with the application.

The show() method belongs to the class MessageBox, of the System.Windows.Forms namespace. Import this namespace before you work with the MessageBox class, so you don't have to specify the fully-qualified name. As print and System.Console are available only from JScript .NET code that is compiled and run from the command line, so is the System.Windows.Forms namespace. It is not available from ASP.NET pages or from Code Behind JScript .NET code.

To learn more about JScript .NET and ASP.NET, go to Column 116, JScript .NET, Part IX: Displaying Information.