January 2, 2014

Debugging a Javascript in ASP.NET

There are two ways you can debug a javascript code in ASP.NET (visual Studio IDE)
I. Usingthe Internet Explorer Process  in the Attach to Process window
II. Using the debugger keyword.
Method I
  • In the Visual studio IDE open javascript .js file  and a breakpoint at the line you want to start debugging the code.  Now click on the menu (Debug | Attach to Process) on the top to open the Attach to Process dialog window (see below) select the  Internet Explorer process (iexplore.exe) from the list of available process a. Execute the code you want to debug in Internet Explorer.
Method II
  • In the Visual studio IDE open javascript .js file  and type the keyword debugger where you want the code to break in to debugging. this
  •  . Write your JavaScript and place the debugger keyword where ever you want the code to break into debugging. The JavaScript interpreter hits this  keyword and halts execution and returns the control back to the IDE. This is like setting a breakpoint inside of Visual Studio.
Note: you must enable script debugging in Internet Explorer to be able to debug. Go to Internet Options inside Internet Explorer and then go to the Advanced tab. Uncheck Disable script debugging (Internet Explorer).

No comments:

Post a Comment