views:

377

answers:

2

In the question Why will Visual Studio 2005 not debug my javascript? I learned that debugging is possible in Visual Studio 2005 but you have to start debugging your application and then press CTRL-ALT-N to open the Script Explorer to set break points, etc.

However, even with the following simple code, when I press CTRL-ALT-N, the Script Explorer window is totally blank. According to all the articles I have found on the subject, it should have e.g. in my case "main.js" (I imagine it is like debugging in Firebug) but it is blank.

What else do I have to do to Visual Studio 2005 so that the Script Explorer shows my running javascript files?

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"&gt;

<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.");
}
+1  A: 

Try attaching your Visual Studio to MSIE via Debug > Attach to process (not sure if it is there in VS2005, look around).

When attaching to process make sure that you check script option.

Rashack
A: 

The easiest way to get started is:

  • Open IE7
  • Goto the menu Internet Options > Advanced
  • Uncheck "Disable script debugging"

To add a break point in a javascript add "debugger;" in your code. Open a page that references that script in IE7, and a popup will come up asking you if you want to debug your script in Visual Studio

<script type="text/javascript">

debugger;

// put your code here

</script>
howardr