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=3.5.0.0, Culture=neutral,   
4:           PublicKeyToken=B77A5C561934E089"/>  
5:        <add assembly="System.Web.Extensions, Version=3.5.0.0,   
6:            Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>  
7:        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0,   
8:           Culture=neutral, PublicKeyToken=B77A5C561934E089"/>  
9:        <add assembly="System.Xml.Linq, Version=3.5.0.0, 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));    
     }  
   </script>  

0 comments:

Post a Comment