Search code examples
javascriptvisual-studiodebuggingvisual-studio-2005

Why will Visual Studio 2005 not debug my JavaScript code?


In this very simple ASP.NET application, Visual Web Developer 2008 Express CAN debug the JavaScript code fine, but the full version of Visual Studio 2005 CANNOT debug it, namely: when I click on a line in the main.js file it gives me a red circle with a question mark on it, the mouse hover revealing: "This break point will not be reached, no symbols were loaded for this document."

What do I have to do to my Visual Studio 2005 so that it debugs JavaScript code like my Visual Web Developer 2008?

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestJavascriptDebugging2005._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
            <script type="text/javascript" src="javascript/main.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <p>This is HTML and <script type="text/javascript">test()</script>.</p>
                <p><button onclick="doIt(this)">Test</button></p>
            </div>
        </form>
    </body>
</html>

javascript/main.js:

function test() {
    document.write("this is from javascript code2");
}

function doIt(element) {
    alert("This is the javascript function2.");
}

Solution

  • Check if the following things are followed:

    i. Enable script debugging in IE.

    ii. Open the client side script in the script explorer, and there you are happy debugging.

    For details on how to accomplish this, please go through the following link from which I originally picked up this trick.

    1. Debugging client javascript in VS2005.
    2. A Kb from Microsoft explaining the same.