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.
Need help with Windows Dedicated Hosting
? Try Server Intellect
. I'm a happy customer!
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:
- Right click the project in your Solution Explorer.
- Select Add New Item...
- Choose a Web Form.
- Name it Default.aspx.
- 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:
- Open Default.aspx up to Design mode.
- Drag and drop a Label onto the Web Form.
Next, we want to open the Default.aspx.cs code behind file up for editing and add the following code to the Page_Load event method:
protected void Page_Load(object sender, EventArgs e)
string txt = "Hello Label";
Label1.Text = txt;
Next, we need to add a breakpoint to the 'Label1.Text = txt;' line of code.
We used over 10 web hosting companies before we found Server Intellect. Their dedicated servers and add-ons were setup swiftly, in less than 24 hours. We were able to confirm our order over the phone. They respond to our inquiries within an hour. Server Intellect's customer support and assistance are the best we've ever experienced.
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.
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
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 for us to easily view and modify data during runtime and are an essential part of debugging in Microsoft Visual Studio 2010.