Setting BreakPoints in Visual Studio 2010 to troubleshoot C# and ASP.NET code

Home > Blogs > Developer Visual Studio / ASP.NET > Setting BreakPoints in Visual Studio 2010 to troubleshoot C# and ASP.NET code

Setting BreakPoints in Visual Studio 2010 to troubleshoot C# and ASP.NET code

Like This Blog 0 Spike Xavier
Added by October 8, 2011

This a step by step guide on how to set breakpoints in Visual Studio 2010 in order to better troubleshoot c# and asp.net code.

Create a New Solution and add some code.

media_1316712467688.png
I created a new web site in Visual Studio and added a master page called default.master and added a theme folder in which I placed a CSS file called main.css. I then made an entry in the web.config so that the web site will use this theme. I have added an asp:BulletedList control to the default.aspx page and written some code in the Page_Load event of default.aspx, which populates the BulletedList Control (BulletedList1) with content.
 

 

Here is a screen shot of the default.aspx.cs code file.

media_1316712812859.png

I create a string array called courses and populate it with the current courses I teach at Interface Technical Training. On the Page_Load event, if the page is not a post back, I populate the BulletedList1 server control with the values from the array.

 

 

Here is the asp.net code showing the bulleted list control.

media_1316712948632.png

 

I use the keys Ctrl + Shift + F5 to build and run the web application on the local web server (built in to Visual Studio 2010) so that I can preview the page.

media_1316713088042.png

 

 

Adding the BreakPoints – I go back to the default.aspx.cs file in Visual Studio 2010 and I click in the left column to add a breakpoint at the beginning of the loop

media_1316713199466.png

I'll build my project again just to make sure i have the latest version going by hitting Ctrl + Shift + F5, when that's done I'll click on the Debug Green Arrow to debug the application.

media_1316713357542.png

The first time I did this I got a message asking if I wanted to modify the config file to allow debugging. I said o.k. (no screen shot of that) I always go through a checklist before deploying to production to make sure to deal with settings like this that might have changed throughout the development process by the way.

 

 

Now the application is in Debug mode and will stop when it gets to the breakpoint (in my case line 15). Depending on how the Visual Studio work area is configured in most cases the Locals window will appear at the bottom.

media_1316713556507.png

I click on the plus sign next to courses to expand the courses array and see the values.

 

 

Now I click on the Step Into Icon at the top and watch the Locals Window.

media_1316713743123.png

This starts to run the code one piece at a time.

 

 

The foreach loop starts.

media_1316715121062.png

I keep pushing the step into icon (or push F11) in order to progress through the code, all the while watching the values in the Locals window.

 

 

As I go through the values of item change in the Locals Window.

media_1316714006850.png

 

Finally when the loop is done I'm sent to the Page_Load of the Master page and then to my user controls and finally to default.aspx where my page loads.

media_1316714129336.png

I go back to Visual Studio and my breakpoint is gone. If it wasn't, I'd simply click on it again to remove it.

 

 

That's how you add a breakpoint(s) in Visual Studio 2010!

media_1316714318842.png

 

 

Videos You May Like

How to Build in a PSMethod to your PowerShell Code

0 65 0

In this video, PowerShell instructor Jason Yoder shows how to add Methods (PSMethod) to your code using free software that’s added into the PSObject. For instructor-led PowerShell courses, see our course schedule. Microsoft Windows PowerShell Training Download the Building Methods PowerShell script</a> used in this video. <# ╔══════════════════════════════════════════════════════════════════════════════╗ ║ ║ ║ Building Methods ║ ╟──────────────────────────────────────────────────────────────────────────────╢ … Continue reading How to Build in a PSMethod to your PowerShell Code

Configuring Windows Mobility Center and How to Turn it On and Off

1 1402 1

Video transcription Steve Fullmer: In our Windows training courses, we often share information about the Windows 8.1 Mobility Center. Mobility Center was introduced for mobile and laptop devices in Windows 7. It’s present and somewhat enhanced in Windows 8. Since we don’t have mobile devices in our classrooms, I decided to take a little bit … Continue reading Configuring Windows Mobility Center and How to Turn it On and Off

How to use AWS CloudFormation templates to automate solutions inside Amazon AWS

0 380 0

  In the AWS Class here at Interface, we actually build fully automated solutions with AWS CloudFormations. Here’s an overview of using AWS templates using CloudFormation. CloudFormation is basically an “infrastructure-as-code tool” where you can go into a declarative document and define all the resources that you want and feed the document into the CloudFormation … Continue reading How to use AWS CloudFormation templates to automate solutions inside Amazon AWS

Write a Comment

Share your thoughts...

Please fill out the comment form below to post a reply.