Object | Script Tracking Events
When an ASP page uses the scripting object model, individual script objects trigger events to react to state changes (such as recordset1_ondatasetcomplete) or user behavior (such as Button1_onclick). Typically, you need to know when your own scripts and events triggered by the Scripting object model are executed.
To do this, open event tracking by setting the @trace or @trace event option to true. If you make the event trace effective, when the event occurs, the event information is written to the ASP page. For example, part of an ASP page might look like this:
Event Trace:thispage fired OnInit event.
Event Trace:recordset1 fired Ombeforeopen event.
Event Trace:recordset1 fired onrowenter event.
Event Trace:recordset1 fired ondatasetchanged event.
Event Trace:recordset1 fired ondatasetcomplete event.
(etc)
To determine when your script executes, include Response.Write statements at important points, as shown in the following script. This example sets an argument for a recordset that is based on the information in a text box. Each step is reported by displaying it on the page.
Sub Btnquery_onclick ()
Recordset1.close ()
Response.Write ("Finished closing recordset.")
Recordset1.setparameter 1, Txtlastname.value
Response.Write ("Finished resetting query parameter.")
Recordset1.open ()
Response.Write ("Finished reopening recordset.")
End Sub
By using the JScript conditional compilation command, you can specify that the Response.Write statement appears on the page only if you set debug options. For example, in the following code block, the Response.Write statement is executed only if the @trace option is set to true:
@if (@trace)
Response.Write ("Ready to set SQL statement parameters.");
@end
You may not be limited to debugging options-you can also create your own condition tags, as shown in the following example:
@set @trace_custom = True
' ... other script
@if (@trace_custom)
Response.Write ("Ready to set SQL statement parameters.");
@end
Note that you must set all debugging conditions to false before you turn your page into a product. For more information on conditional compilation, see the @if and @set commands in the Microsoft Scripting Site Statement section. The website address is http://msdn.microsoft.com/scripting/default.htm? /scripting/jscript/doc/jstoc.htm.
Trace warning
To make the script object as robust as possible, and to make the fewest unnecessary information displayed on an ASP page, script objects typically do not report non-fatal errors. For example, if you pass an invalid value to a Script object method, and the value does not completely fail the object, the object is often executed without error messages. However, when you develop an application, you will generally wonder if a possible error has occurred in the script object. Sometimes, an error that is not reported can create a different problem during page execution, making it more difficult to debug the page.
The workaround is to track the warning by setting the @trace or @trace warning option to true. If a script object encounters a possible problem, it writes information to the page in the following format:
WARNING TRACE:
FILE:recordset.asp
FUNCTION:Recordset1.open ()
Description:recordset is already open.