|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Debugging Client-Side Scripts in a Web Page
Using the Visual Studio .NET debugger, you can perform the following tasks when debugging client-side script in a Web page:
- View the source code of the Web page (.htm, .html, .asp, .aspx) that you are debugging.
- Control the pace of script execution with breakpoints and stepping.
- View and change variable and property values with several debugging windows including the Command window and Watch window.
- View and control script flow with the Call Stack window.
Note To debug script you must enable script debugging in Internet Explorer.
When you work with the Microsoft Visual Studio .NET debugger, you see the script that you are debugging in a read-only editor in the IDE. You cannot change the text in the window — documents are read-only while you are debugging. However, you can save the document under a new name, then open the document and modify it.
To control program execution, you set breakpoints, which are places where the script should pause and call the debugger. When you set breakpoints, the line containing the breakpoint is highlighted in the editor.
After setting a breakpoint, you run the document containing the script. When execution reaches the first breakpoint, the script pauses and starts the debugger. The current line is marked in the editor with a yellow box.
After reaching a breakpoint, you can execute, or step into, individual lines in your script. As you step through lines, the script executes and you can see the effect of each line.
If you reach a point in your script that calls another procedure (a function, subroutine) you enter (step into) the procedure or run (step over) it and stop at the next line. At any point, you can jump to the end (step out) of the current procedure and proceed to the next breakpoint.
While debugging, you can view and change the values of variables or properties. Because you are making changes directly to a running script, you can affect the way that the script executes by changing values in it. After changing values, you can continue with the script and see the effect of your change.
To view and change values, you use the Immediate window. You can evaluate any expression in the window and can enter script commands and see their effect. You can enter commands in the language of the script currently executing.
The Call Stack window allows you to trace the procedures and functions that are currently executing. While debugging, you can view the flow of control from procedure to procedure. You can also select a procedure in the call stack and jump directly to it and then continue running the script.