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

The Autos/Locals windows allow developers to see detailed data about objects and variables during runtime. These can be used to verify or even change data during runtime to give developers more control over debugging their applications.

Creating a Web Site

To demonstrate the Autos/Locals windows, we will need to make a simple website that allows us to add a breakpoint to the code behind to pause the program during runtime so we can review the data at a given point during runtime. At this point, I have created a new ASP.NET Empty Web Site. Next, we will add a Web Form. To do this:

  1. Right click the project in your Solution Explorer.
  2. Select Add New Item…
  3. Choose a Web Form.
  4. Name it Default.aspx.
  5. Click Add.

Next, we want to add a Label to our Web Form that we can modify in the codebehind with C#. To do this:

  1. Open Default.aspx up to Design mode.
  2. Drag and drop a Label onto the Web Form.

Next, we need to add a breakpoint to the ‘Label1.Text = txt;’ line of code.

The Autos Window

Let’s go ahead and run the website with debugging now and notice that it will stop at the breakpoint we added earlier. To view the Autos window, select from the top menu Debug -> Windows -> Autos. You should now be viewing something that looks like this:

The Autos window shows variables used in the current statement. We see the two local variables that we have in our method, our txt string and our Label1.Text that we were modifying in the line of code that we stopped on. The Autos window displays the current values of these as well. To view these values in their own window you can select the down arrow next to the magnifying glass in the Value column and select Text Visualizer. This will bring up a new window that looks like this:

This can be useful when the data does not fit in the Values columns. Also, you can even modify the values of our current data in the Value column by double clicking the cell you want to modify, replacing the text, and hitting enter. If you double click the Value column, replace the text with “Hello World”, and hit enter, you will see that the value of the Label1 is actually changed here.

Also, you can click the ‘+’ next to objects that contain complex datatypes to view everything inside of them.

The Locals Window

If we want to view the Locals window we can simply select from the top menu Debug -> Windows -> Locals. Locals is similar to the Autos window, but it displays the current local variables instead of just variables from the current statement. Notice that the data displayed here is slightly different and that we also see the paremeters from the Page_Load event method.

These windows allow fo us to easily view and modify data during runtime and are an essential part of debugging in Microsoft Visual Studio 2010.
Download Source Files