This tutorial is the eigth part of the ASP.NET Web Site Debugging tutorial series. This tutorial will demonstrate how to use stepping in Microsoft Visual Studio 2010 with ASP.NET 4.0 and C#.

What is Stepping?

Stepping in Microsoft Visual Studio is what allows you to pause a program at a specified point during execution, and from there step through the code line by line. This is extremely powerful when debugging because it allows you to figure out what is going on in your program at every given point of execution. The following are the three different ways to step through code:

Name Description
Step Into This allows you to go line by line through the code, while stepping into any nested methods.
Step Over This is similar to step into, however it avoids going into any nested methods.
Step Out Step out will execute code until the end of the current method you are in.

Using Stepping

To demonstrate how to use each of these different types of stepping, we will create a simple web site that we will add some test code to that we can step through. To begin, create a new ASP.NET Empty Web Site and:

  1. Right click the project in your solution explorer.
  2. Select add new item…
  3. Select a web form.
  4. Name it ‘Default.aspx’.
  5. Click add.
  6. Open Default.aspx.cs up for editing.

Next, we need to add the following code to the Page_Load event method:

Finally, add in the following method to the Default.aspx.cs class:

To demonstrate how to use stepping, we will need to stop the program during execution by using a break point. Go ahead and add a break point on the first call to testMethod() in the page load event method.

To begin, load up the web site with debugging and notice that it stops where we added the break point.

  1. Go ahead and hit F11 to step into the method call.
  2. Notice that we are brought down to the test method we added.
  3. Use F10 to step over a few lines of code.
  4. Notice that at any given point you can mouse over our x variable to see its current value.
  5. Use Shift + F11 to step out of the test method.
  6. Notice we we brought back out to our page load method.
  7. Use F10 to step over the second call to our test method.
  8. Notice that instead of going into the method, we have simply skipped over it.

These are the three different ways to step through your code line by line. Using all three of them, we can go to any given line of code that is executed in our web site. Furthermore, at each new line of code that is executed you can get the data from everything that is currently going on within the web site. This allows us to debug at an extremely low level so that we can easily understand what is going on within our web site.
Download Source Files