views:

2871

answers:

13

I just saw this mentioned in this thread and didn't know it could be done. I'm a VS newbie, so how do you do it? Is there a separate debugger for Javascript? I know how to work the one for code-behind pages... I usually use Firebug to deal with debugging JS.

EDIT: I'm using VS 2005.

A: 

In IE. Select View -> Script Debugger -> Open.

That should do it.

Ray
+2  A: 

TechRepublic has a good walk through - http://blogs.techrepublic.com.com/programming-and-development/?p=672

Christian Hagelid
+2  A: 

Visual Studio 2008 ASP.NET projects has debugging enabled by default. You can set breakpoints within your .js file while the website/web app project is run in the ASP.NET debug server.

Jon Limjap
How to configure VS if debugging from scratch doesn't work?
abatishchev
A: 

@Jon Limjap Ah well, I use VS 2005. I don't have the luxury of 2008 yet. :)

Bryan Denny
+4  A: 

I prefer using FireBug for projects I can't use 2008 on.

brendan
+5  A: 

To debug in VS 2005, make sure that "disable script debugging" is unchecked. Then load your webpage in IE. From the debug menu inside of VS2K5, select "Attach to process" and pick the instance of IE that has your web page loaded.

Alternatively, the FireBug team has been working on a "lite" version that you can include either as a script in your page or by launching it via a bookmarklet from your browser. It doesn't provide the full debugger that Firebug does, but it gives you a console and a command line from which you can inspect variables and log things to the console.

http://getfirebug.com/lite.html

ScottKoon
A: 

Usually you know where you are having problems, so you can set a breakpoint in your javascript code by placing the keyword "debugger;" on a line in your javascript code (obviously without the quotes) to set a breakpoint.

When you get to it in IE, it will ask you if you want to debug and prompt you to choose a debugger from a list, hopefully you will see Visual Studio in that list (both a new instance as well as your currently-running instance) - if you are using FireFox with FireBug, it will automatically stop execution on that line and you will be within the FireBug debugger, not Visual Studio.

You will want to do the following to setup IE for doing this - from within IE, follow this menu path: Tools > Internet Options > Advanced Tab > Uncheck the "Disable Script Debugging" options.

Jason Bunting
A: 

Yeah using Microsoft Script Editor is a an option if you have Office XP or Office 2003 installed. In IE uncheck Disable Script debugging (Internet Explorer) and Disable Script debugging (Other).

Restart IE. In View menu you will have a new item, "script debugging", choose open. You will be given a choice of VS2005 or New instance of Microsoft Script Editor, choose that and give it a go.

Edit: try this link for a tutorial

John Nolan
A: 

You can set a breakpoint within javascript in VS2005 but in addition to debugging needing to be enabled in IE, you can only set the breakpoint in a .js file. you cannot debug any inline javascript code.

I also sometimes have problems when trying to debug my javascript when using the attach process method to go into debugging. I will normally use the "Start debugging" green arrow. You will know that your code will stop at the breakpoint in your .js file if the breakpoint icon (Burgandy Circle by default) is filled in. If it's not filled in you will never stop there.

Finally, make sure you have debugging enabled in your asp.net configuration settings.

Haydar
A: 

Just make sure you have 'Disable Script Debugging' unchecked, and just hit F5 to start debugging in VS2005 or 2008.

I would also note that if you have your JavaScript inside the .aspx page you will have to find it via the script explore. However if you have it in a separate .js file you can just put a break point on it like you would any .cs file.

David Basarab
A: 

I usually use Firebug to deal with debugging JS.

Unless you need to debug in IE, there's no need to stop using Firebug. It works with JavaScript in ASP.NET pages just as well as it does with any other type of page.

Visual Studio's JavaScript debugging is alright, but really cannot compete with the full range of client-side information that Firebug aggregates.

Dave Ward
A: 

I have Visual Studio 2005, but it doesn't open automatically when there is JavaScript error. On the IE also I cannot see view-ScriptDebugger option. Can anyone help.

A: 

Debugging client JavaScript in Visual Studio 2005

Add following code start of the Java script
debugger

link text