From http://www.code101.com/Code101/DisplayArticle.aspx? Cid = 67
Introduction
Asp.net has come a long way from Asp on login facets, especially debugging. if you have work with ASP.net for a while and go back to work on ASP you wowould miss a lot of feature and debugging is the most you miss. visual studio.net is an awesome IDE tool, allows you to step through the your server code, stored procedure and JavaScript too-Did you know this?
There is a growing demand for highly scalable, reliable and rich user experience web application, javaScript has a major role to play on the client side scripting to avoid post back and never the less to avoid view state moving back and forth the wire in ASP.net applications.
Lets dive in and see how to debug JavaScript
IE browser settings
This work onlyInternet Explorer 6And VS. NET The first thing to do is to get browser settings right. Open IE and select the following menusTools | Internet Options | Advanced | Disable script debugging (uncheck)
Back to ASP.net application
Let us try out a quick sample. Open an Asp.net project Drop a HTML button on the web form and write a javascript to add two numbers and raise an alert message on the client.
<script language="javascript"> function Sum() { var a=10; var b=20; var c=a+b; alert(c); }</script><INPUT type="button" value="Button" onclick="Sum()">
Now run your project and when you see you web page go to the design mode of visual studio and selectDebug | Windows | Running events entsFrom the Debug menu. This opens up a Running events explorer click on the JavaScript. aspx file and place the break point on the line of Javascript you want to debug.
From here are you cocould debug like any server code-use the "Locals Window" to see all the objects or Immediate window to change values of the variables
Debugging JavaScript in External files
ASP.net debugger also allows us to debug javascript present in the in external files. Move this Javascript Sum () function to a file named JScript1.js and refer the JScript1.js file in the webpage
<script language="javascript" src=/Code101Demo/JScript1.js>
Run the project and repeat the steps Debug | Windows | Running events from the Debug menu. in Running documents explorer now you wocould see two files JScript1.js and JavaScript. aspx. double click on the JScript1.js and set the break point as shown in the screen shot.
This technique is very handy not only to debug but also to learn a lot about how the Validation controls and Smart Navigation works in ASP.net. for those who are new to ASP.net the above-mentioned functionality are implemented using JavaScript file WebUIValidation. js and SmartNavIE5.js
By default they are located in the \ aspnet_client \ system_web \ %0_3705_288this folder name %0_3705_288 represents the CLR version number so each version of CLR wowould have a different client JavaScript files.
Debugger key word
Instead of manually setting the break point we cocould use the bedugger key word on the line to break. this technique comes handy on the scripts that run when the form loads. lets try it out on the previous code.
function Sum() { var a=10; var b=20; var c=a+b; debugger; alert(c); }
Conclusion
Debugging JavaScript is really a cool feature of VS.net this saves developer a lot of time and frustration when writing JavaScript. Beside this it gives you chance to peeking into the plumbing activities of client side validation controls.