Erx_VB.NExT.Coder
Erx_VB.NExT.Coder

Reputation: 4856

How to set JavaScript breakpoints in Visual Studio 2008 or Visual Studio 2010

I'm trying to debug JavaScript code using Visual Studio 2010, but I can't set breakpoints.

How can I do this?

I just noticed something, every time I try to call a function, no matter what function, in JavaScript, somehow jQuery and Microsoft's Ajax framework JavaScript captures it and checks if the document is ready (document.onready or other) and never returns the control back to the function I'm calling! Why on earth is it doing this? I've never asked for it to!

All I have are references to these libraries, script/link references as you do on the top of your master page.

This is ridiculous, how do I fix it?

Upvotes: 14

Views: 19476

Answers (3)

Dave Archer
Dave Archer

Reputation: 3060

If you're attaching to a process, you can specify that you want to attach to script in the dialog that comes up. But then it'll be only script and not managed code.

Just use Firebug in Firefox.

Upvotes: 0

rahul
rahul

Reputation: 187090

Use the debugger; statement before the line where you want to stop execution and debug.

Example

var test = "testString";
debugger; // stops execution and can start debugging
test += "newly added";

Upvotes: 8

kime waza
kime waza

Reputation: 511

If your script is in a separate script file (.js), then you can just use F9 to set a breakpoint on a line.

You can't set a breakpoint if the script is incorporated in another file like an aspx file. For cases like that, use the debugger; javascript statement to force a break at a certain spot.

Also make sure that you are working with the latest version of your javascript file, do a Ctrl-F5 in IE if necessary to force a fresh reload of the file.

Upvotes: 19

Related Questions