Methods and techniques for debugging asp.net applications
Source: Internet
Author: User
People who used to use ASP to develop Web applications must know how troublesome it is to debug Web applications. In ASP, debugging is painful and typically includes values that use the Response.Write () method to output variables. So ask yourself: how many times have you forgotten to delete a debug statement before the application is in the program?
With. NET Framework components have changed radically. In. NET, you can use visual Studio. NET to track the execution of the entire WEB application, or to use the Trace class in the System.Web.TraceContext namespace. This article demonstrates how to use the Trace class to assist with your debugging efforts.
Using the Trace class
Asp. NET contains a trace class that helps track the flow of information in your application. Instead of debugging with a response object, you can now use the Trace class to print out debugging information.
To demonstrate its use, we first build a asp.net Web application and place a button and a ListBox control on the default WebForm1 (as shown in Figure 1). Populates the ListBox control with three items and sets its AutoPostBack property to True.
Figure 1. Populating the default WebForm1
For this article, I want to track the execution flow of the application. First, the trace is activated, and the page directive requires that the trace attribute be set to true (switch to view HTML source mode), as shown in Figure 2.
Figure 2. Activate tracing
Next, I insert the trace statement in the form's Load event so that I know if postback has occurred. The postback event is one of the most confusing features in ASP.net, and it often leads to the failure of the first ASP.net developers.
Private Sub Page_Load (ByVal sender as System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' Place the user code for the initialization page here
Trace.Write ("Page Loaded")
If not IsPostBack Then
Trace.Write ("Not in a postback")
' Perform some action when the postback occurs
Else
Trace.Write ("In a postback")
' Perform some action
End If
End Sub
I also want to know whether the postback occurred when the listbox was selected:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.