You can also insert
Trace statements into your application. For example, in the
following code I have inserted two
Trace statements: one to display a warning when
the user did not enter a string for the TextBox control, and another to simply display
the contents of the TextBox control:
Protected Sub Button1_Click( _ ByVal sender As Object, _ ByVal e As System.EventArgs) _ Handles Button1.Click If TextBox1.Text = "" Then Trace.Warn("Empty string for textbox1") Else Trace.Write(TextBox1.Text) End If Label1.Text = "Hello " & TextBox1.Text End Sub
When run, notice the red warning text (see Figure 7) when the button is clicked.
Figure 7. Displaying a warning message in red
But if you type some text into the TextBox control, the trace message will be printed in black (see Figure 8).
Figure 8. Displaying trace information
The nice feature about the
Trace class is that when it comes to time to deploy the
application, you can simply turn off tracing by setting the
Trace attribute to "off;"
there is no need for you to remove the trace statements.
Besides tracing, you also have the ability to step through the execution of your application code. Figure 9 shows that you can perform debugging on an ASP.NET web application in real time.
Figure 9. Debugging an ASP.NET application using Visual Studio