Pages

Tuesday, August 10, 2010

JavaScript Debugging [Visual Studio]

The various steps to enable java script debugging is as given below:

1. ASP.Net application configuration to enable debugging
    Open the ASP.Net application in Visual Studio and open ‘web.config’ that created with application and find the tag ‘compilation’ in the file. The line may look like as below:

    If debug=”false” then set it to debug=”true” and resulting will look like as below:

    2.    IIS Configuration to support debugging
    Start --> Settings --> Control Panel --> Administrative Tools --> Internet Information Services (IIS)
    --> Expand Web Sites --> Default Web Site --> right click on your web project required to be debugged and select properties --> click Virtual Directory Tab --> click configuration button --> and in the new opened window click Debugging Tab and ensure that two check boxes labeled 1. “Enable Server Side Script Debugging” 2. and “Enable Client Side Script Debugging” to be checked.


    3. Configure Web browser for debugging:
     Open IE and click on menu Tools --> Internet Options --> Advanced Tab --> if ‘Disable Script Debugging (Internet Explorer)’ and Disable Script Debugging (Other)’ check boxes are checked then uncheck those two check boxes and click button OK. (Refer below Screen Shot)



    4.    Attaching ASP.Net process to Visual Studio:
    If application is opened in VS 2003. Then under Tools menu select attach a process and select aspnet process and attach the process to the application.
    If you open the project in VS 2005 or later then it does not require you to explicitly attach the aspnet process. In the JavaScript add a break point where you want to debug and also add a break point in the .vb or .cs code file where the JavaScript function is called.
    Now run the application. The application running will break at the break point within the javascript code as required.

    Features

    The JavaScript debugger presents many standard debugging features. The following list provides a review of some of these features.
    • Breakpoints: Breakpoints allow you to stop code execution at specific points within the source code. JavaScript breakpoints work just like C#/VB breakpoints.
      Breakpoints are set/cleared by clicking to the left of the code within the IDE; by using the Debug menu or by using the Breakpoint Context menu available by right-clicking on the code. In addition, you may create conditional breakpoints to allow you to define conditions for the breakpoint, as well as set up a macro to run or a message to print when the breakpoint is triggered.
      Breakpoints are viewable in the Watch window located by default in the lower left of Visual Studio 2008.
    • Call Stack: The Call Stack tab in the lower right of Visual Studio 2008 allows you to view what is being called when the ASP.NET page is loaded/running.
    • Locals: The Locals tab in the lower left of Visual Studio 2008 allows you to view the values of variables and objects during script execution. Also, you may change the contents of one of the local variables while the page is running.
    • Execute code: The Immediate Window tab in the lower right of Visual Studio 2008 allows you to execute JavaScript code on-the-fly during page execution.
    The Debug drop-down menu within Visual Studio 2008 provides a Windows submenu that allows you to define what windows to display while debugging. For example: Locals, Watch, Call Stack, and Immediate Window.
    The most used feature during debugging is often breakpoints because you can use them to stop code execution and examine the state of variables and objects at that point in the script. Breakpoints provide a number of features (which are available via the Debug drop-down menu during a debugging session) for their use.
    Code execution stops at each breakpoint — unless it is a conditional breakpoint whose condition has not been met. Once the code is halted, you may choose to continue one line at a time or until the next breakpoint is encountered.
    The debugger is actually enabled via the Debug menu in Visual Studio 2008. You go to Debug | Start to begin a debugging session or press [F5]