Debugging a Global.asa file differs from debugging .asp files in
these ways:
Before you can debug script in the Global.asa page, you must enable debugging for ASP pages.
To enable script debugging in ASP pages
To debug the Global.asa file, you can call the debugger from a script or respond to an error.
To call the debugger from the Global.asa file
ûorû
Stop
in VBScript or debugger
in JavaScript. Place the statement at the beginning of the procedure, before any statements that you will want to step through.
When the application starts or when a user starts a new session, the corresponding procedure in a Global.asa file will run. The debugger will start when the Stop
or debugger
statement is executed. You can then step through the procedure normally, use the Immediate window to evaluate expressions and set values, and so on.
If there is an error in a Global.asa file (either a syntax error or runtime error), the server stops the procedure containing the error. If the debugger is enabled for that ASP application, the server prompts you to start the debugger and displays an error message. If the debugger is not enabled for the ASP application, an error message is sent to the client browser. In either case, the procedure containing the error stops.
To debug Global.asa script in response to an error
If Visual InterDev is not already running, it is launched. The debugger attaches itself to the script with the error and displays the page in the editor.
You cannot stop and restart the script by refreshing a Global.asa file. To rerun Application_OnStart or Session_OnStart procedures, you must refresh the file or trigger the events again or otherwise restart the application.
To rerun all procedures in the Global.asa
This restarts the application and session, which runs the procedures in the Global.asa file again.
To rerun Application_OnStart procedures
You can rerun Session_OnStart procedures by restarting a session.
To rerun Session_OnStart procedures
Session_OnStart
event procedure.ûorû
Session
objectÆs Abandon
method, and then start a new session.Debugging script allows you to find errors in your script, such as syntax errors, run-time errors, and logic errors, before you publish that script to the World Wide Web. You probably already know how to set breakpoints and how to step through lines of script. Now you can see how to accomplish these tasks using Microsoft Visual InterDev.
In Visual InterDev, debugging script consists of some or all of these steps, once you have added script to a page:
Debugging client script is an easy way to become familiar with debugging in Visual InterDev. Client-side script is processed on the browser, while server-side script is processed on the Web server. For more information about client- and server-side script, see Debugging Client Script and Debugging Server Script.
The sample client script, located between the <SCRIPT>
</SCRIPT>
tags in the example below, validates the length of password entries made in a simple form. The remaining HTML tags define the form and do not participate in the script debugging process.
To use the script below, copy and paste the script and HTML into a new .htm file using Source view of the HTML editor. For more information, see Editing Script.
<SCRIPT LANGUAGE="JavaScript">
function validatePassword(){
var password;
password = document.frm1.txtPassword.value;
alert("You entered " + password);
if (password.length < 4)
alert("You must enter 4 characters or more!");
else {
frm1.submit() ; }
}
</script>
<FORM NAME="frm1" METHOD="Post" ACTION="Process.asp" ONSUBMIT="validatePassword()">
Please enter your password:<br>
<INPUT TYPE="Password" NAME="txtPassword">
<INPUT TYPE="Submit" NAME="btnSubmit">
</FORM>
Note JavaScript is case sensitive, so the sample script above must appear exactly as it does here in your .htm file.
The script checks that the password length is four characters or greater. The script generates a message box listing the password the user entered. If the password is four characters or greater the user is then redirected to the page called by the Action element of the Form tag.
If you haven't created Process.asp, the browser will display the object not found error. If the password is less than four characters, a message box appears indicating the character length requirement.
To specify a place in script where you want to stop and examine the state of the process, you can use breakpoints. Breakpoints indicate the line of script you want to stop on in the program. You can then step through, step into, or step over lines of script individually to find errors. Breakpoints show up as red octagons to the left of a line of script in Source view.
Note To debug client scripts in Microsoft Internet Explorer, you must be using Internet Explorer 4.0 and debugging must be enabled. For details, see the Internet Explorer documentation.
To set breakpoints
A red octagon appears to the left of the line of script.
Note You can also set or remove a breakpoint by placing the cursor in a line of script and pressing F9.
To launch the debugger
The Processes dialog box appears.
Microsoft Internet Explorer and your machine name appear in the Debugged Processes area.
The script executes until Internet Explorer reaches the breakpoint. When Internet Explorer reaches the breakpoint, it stops and displays the source script in Source view.
A yellow arrow superimposed over the breakpoint icon indicates the line of script where the debugger stopped.
For more information, see Breakpoints Dialog Box or Debugging Client Script.
To execute script one line at a time, you can use Step Into. After stepping through each line, you can view the affects of the statement by looking at the page in Internet Explorer.
To step into lines of script
<FORM NAME="frm1" METHOD="Post" ACTION="Process.asp" ONSUBMIT="validatePassword()">
Note When you place a breakpoint in the line of HTML above, you are actually specifying that the script stop executing when you click the Submit button, ONSUBMIT="validatePassword()"
.
Internet Explorer reaches the breakpoint and switches to Source view. A yellow arrow appears superimposed over the breakpoint icon.
The following line of script is highlighted:
alert("You entered " + password);
Internet Explorer executes the alert script and displays the message box.
Internet Explorer reaches the next line of script and switches to Source view.
You can continue stepping into lines of script and view the results in Internet Explorer.
To execute procedures in script as a single unit, you can use Step Over. Step Over allows you to skip a procedure or function and step through the next procedure or function.
After stepping over a procedure, you can view the affects of the procedure by looking at the page in Internet Explorer.
To step over lines of script
<FORM NAME="frm1" METHOD="Post" ACTION="Process.asp" ONSUBMIT="validatePassword()">
Note When you place a breakpoint in the line of HTML above, you are actually specifying that the script stop executing when you click the Submit button, ONSUBMIT="validatePassword()"
.
Internet Explorer reaches the breakpoint and switches to Source view. A yellow arrow appears superimposed over the breakpoint icon.
Internet Explorer executed the following script as a procedure unit:
password = document.frm1.txtPassword.value;
alert("You entered " + password);
if (password.length < 4)
alert("You must enter 4 characters or more!");
Internet Explorer reaches the line of script after the procedure unit and switches back to Source view. For more information, see Debugging Your Pages and Stepping Through Code to Trace Execution.
You can change the value of a variable from the Immediate window. When Internet Explorer reaches a breakpoint and switches to Source view, you can then change the value of a variable and view the results in the Locals window.
To change the value of a variable
<FORM NAME="frm1" METHOD="Post" ACTION="Process.asp" ONSUBMIT="validatePassword()">
Internet Explorer reaches the breakpoint and switches to Source view. A yellow arrow appears superimposed over the breakpoint icon.
password="test"
The Locals window displays the new value of the variable you entered in the Immediate window.
For more information, see Executing Commands and Evaluating Expressions in the Immediate Window and Viewing Local Variables in the Locals Window.