JScript .NET, Part X: Displaying Information: Using System.Windows.Forms.MessageBox - Doc JavaScript
JScript .NET, Part X: Displaying Information
Using System.Windows.Forms.MessageBox
You probably know well 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.
The following code greets the user and asks him or her to press the OK
button on two consecutive message boxes:
import System.Windows.Forms; System.Windows.Forms.MessageBox.Show ("Hello! Press the OK button"); MessageBox.Show("Doing fine! Now press the button again.");
The following command-line window shows the code listing, the compilation command of this code (col116ex4.js
), the execution command, and the first message box that pops up. The second command-line window below shows the second message box that pops up after the user clicks the OK
button on the first message box.
Next: How to use <%= %>
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: August 12, 2002
Revised: August 12, 2002
URL: https://www.webreference.com/js/column116/4.html