Question

Possible to set a breakpoint for the code block of javascript like the screenshot below. How can we use them? VS always ignores.

enter image description here

Was it helpful?

Solution

If Internet Explorer is set as the browser when debugging, Visual Studio is, in theory, able to stop at breakpoints set at client side script. To use the feature, you will need to make sure that "Disable script debugging" is checked in your IE Internet Options, Advanced tab.

However, I have found VS script debugging to be a bit flaky; the breakpoint is not always hit, especially with VS2010 or earlier. My personal experience is that it works best in VS2012 or later.

That being said, if you're using VS as the client-side script debugger and you find that your client-side breakpoints are not getting hit, it is best to insert a "debugger;" line prior to the line you would like to break at to ensure that it is picked up by the VS script debugger.

pennstatephil posted a link above that indeed provides more information on the subject: http://msdn.microsoft.com/en-us/library/7seh8d72.aspx

Edit: I'm not able to add comments, but in response to sb9's comment about why one would use IE, I find debugging in Visual Studio a lot more convenient when investigating script behavior before postbacks occur and server-side behaviors occurring immediately after postbacks. Also, sometimes the VS/IE combination will catch errors that Chrome and Firefox/Firebug reports with a nonsensical error message.

OTHER TIPS

In Visual Studio 2017 there is an option to enable/disable script debugging

Just enable it and you should be good to go.

enter image description here

There are seemingly infinite possibilities to why this happens. I just solved this problem after hours of searching.

My particular issue is that my breakpoints were disabled immediately after my coworker enabled bundling (see description here). I had to go into our BundleConfig.cs file and comment out the line that said:

BundleTable.EnableOptimizations = true;

After I did that, they were hit. You'd want to add that line back in for deployments.

Another scenario for the inability of the debugger to stop at the break point is if one uses bundling. To debug JavaScript files, we need to remove bundling.

I hope this will help someone.

Yes you can put the break-point on client side page in Visual studio

First Put the debugger in java-script code and run the page in browser

debugger

Add debugger in java-script code

After that open your page in browser and view the inspect element you see the following view

Client side view of break point in java-script

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top