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

The Immediate window is an extremely powerful debugging tool in Microsoft Visual Studio 2010 that allows you to execute code during runtime. This can be useful for many different tasks such as changing variables or even calling methods during runtime.

Creating a Web Site

To demonstrate the Immediate window we will need to create a simple web site on wich we will add a label and some C# code that modifies it. At this point, I have created a new ASP.NET Empty Web Site. Next, we will want to add a web form with a label on it to our web site. To do this:

  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 up to design mode.
  7. Drag and drop a label onto the web form.

Next, we want to add some simple C# code and a breakpoint to allow us to debug the web site. To do this:

  1. Open Default.aspx.cs up for editing.
  2. Add in the following code to the Page_Load event method:
  3. Add in a breakpoint at the ending curly brace ‘}’ of the Page_Load event method.

Using the Immediate Window

To begin using the Immediate window we need to load the web site up with debugging. Once the web site stops at the breakpoint we added, we want to begin working with the Immediate window. To do this:

  1. From the top menu select Debug -> Windows -> Immediate to view the Immediate window.
  2. In the Immediate window type in ‘strText’ and hit enter. This will display the value of strText.
  3. To change the value of strText type in ‘strText = “Hello World” ‘ and hit enter. It will display the new value of strText.
  4. To change the value of Label1.Text type in ‘Label1.Text = strText’ and hit enter. Notice that you have full access to intellisense here just like you would modifying code in the editor.
  5. Furthermore, we can even execute methods here, to test this type in ‘Label1.ToString()’. This will display the type of Label1.

The Immediate window can be greatly helpful in debugging code by executing methods with different values to test their results.
Download Source Files