UpTheCreek
UpTheCreek

Reputation: 32391

Why can't I set a breakpoint in a ASP.NET view?

If I set a breakpoint in the compiled code (for instance in an action), I can then step through, and eventually am stepping through the generation of the View.

I've found this useful a couple of times, but it's tedious as you have to step through a lot of code to get there.

However, I can't set a breakpoint in view. I just receive the message 'This is not a valid location for a breakpoint' from VS2008. Why is this?

Upvotes: 5

Views: 5007

Answers (4)

Antony Blazer
Antony Blazer

Reputation: 705

Click to the code where you want to debug and than press F9.

Upvotes: 2

jim tollan
jim tollan

Reputation: 22483

UpTheCreek,

Not really a 'nice' way to do it, however, you can insert some 'flip-flop' code in your view that CAN have a breakpoint placed in it and then step from there. This code doesn't neccessarily have to perfom a function (tho obviously, would be useful if it did).

anyway, you don't want the crumbs, so here's the (meal) deal:

<%
    int rspId = 0;
    string uniqPageId = Guid.NewGuid().ToString().Replace("-", "");  
%>

then, simply place the breakpoint at the side of any of those variable definitions.

Not clean and definately a 'jfar' markdown candidate :-)

Upvotes: 1

Dick Lampard
Dick Lampard

Reputation: 2266

Another thing that comes to my mind is to use the debugger; keyword in the view, though I am not 100% sure it will work as in ASP.NET ajax site.

Upvotes: 2

John Farrell
John Farrell

Reputation: 24754

Right click on the code you want to break on and go to "Breakpoint -> Insert Breakpoint".

Why? Must have something to do with the face your not working with a pure code file and hitting the left sidebar doesn't know which block of code to use.

Upvotes: 6

Related Questions