Tuesday, May 3, 2011

Debug JavaScript Code in Visual Studio 2008/2010

Here are the simple steps to debug js code in your aspx markup.

1. Open Visual Studio 2008/2010
2. Click Tools then options
3. Expand debugging node then click checkboxes Manages,Native,Script.
4. In your web.config file,make sure to set compilation debug to true.
1:  <compilation debug="true">       
2:       <assemblies>  
3:        <add assembly="System.Core, Version=, Culture=neutral,   
4:           PublicKeyToken=B77A5C561934E089"/>  
5:        <add assembly="System.Web.Extensions, Version=,   
6:            Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
7:        <add assembly="System.Data.DataSetExtensions, Version=,   
8:           Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
9:        <add assembly="System.Xml.Linq, Version=, Culture=neutral,   
10:           PublicKeyToken=B77A5C561934E089"/>  
11:       </assemblies>  
12:      </compilation>  
5. Choose IE as default browser by right clicking on the .aspx webpage then choose IE as default browser.
6. Place a breakpoint in your js script, then run your code.
 <script type="text/javascript" language="javascript">  
     function myHello()   
       var x = 5;  
       var y = 6; //place breakpoint here or anywhere in your code  
       alert((x + y));    


Post a Comment