How developers Debug script objects in ASP pages (2)

Source: Internet
Author: User
Tags contains object model pack visual studio
objects | script debugging and scripting libraries
Because the script object itself is scripted, debugging scripts you write to interact with the Scripting object model can be complex, for several reasons:

First, when you step through your own scripts with the debugger, you may get into unfamiliar and very complex script library code. Second, if an error occurs inside the script library, stepping through it can be tedious and not necessarily help you pinpoint the error. Finally, sometimes it can be difficult to follow the sequence of events and the flow of control between the script and the Scripting object model.

Now you can debug your application in these environments using the following scripting Object model debugging options:

Catch low-level errors (catch low-level errors)-if a script object such as a recordset encounters an error, it may use detailed error messages to warn you. This option helps you find errors by using components that may fail for external reasons.
Trace events-You may have the page display a list of events that are triggered when they occur. This option helps you to see when the scripts associated with the Scripting Object model events will be executed.
Trace warnings-You may see a warning message describing a possible error, but there are some errors that do not have a warning message and usually occur silently. This option helps you find errors like those caused by passing invalid arguments to a method.
Enables script objects to be debugged
When you create a new ASP page using Visual Studio 6.0, Service Pack 3 and later, the ASP page contains a script block at the top, with debugging options in the script block.

Note For those projects that were created before service Pack 3 and later, you must copy the new script library files to your project.

By default, options are turned off. The script blocks are generally as follows:

<script id=debugdirectives Runat=server language=javascript>
Set this to true to enable debugging or tracing
@set @debug =false
@set @trace =false
</SCRIPT>

Note: Scripting object debugging requires that Microsoft JScript version 5.0 or later be running on the server. You can install JScript 5.0 on the server from the Microsoft Visual InterDev 6.0 CD, or you can get it from the Microsoft Scripting site, which is located in http://msdn.microsoft.com/scripting/default.htm.

To be able to debug, set the options you want to become true. For example, to catch low-level errors, the script block changes as follows:

<script id=debugdirectives Runat=server language=javascript>
Set this to true to enable debugging or tracing
@set @debug = True
@set @trace = False
</SCRIPT>

Note: The debug option block must appear at the top of the ASP page immediately following the @language instruction.

You can set four options altogether, as shown in the following table. Detailed information about the individual (individual) settings is described later in this topic.

Options description
@debug report the selected error in a specific script object.
@trace turn on the following two trace options.
@trace_events turn on event tracking.
@trace_warnings to open a warning message that is usually a possible error that may occur silently.

Note: If you set @trace to True, it will overwrite the @trace_events and @trace_warnings settings. However, if @trace is false, you can switch each tracking option individually. Individual tracking options are not part of the default script block in an ASP page, so if you want to set up separate settings you must add them separately. For example, the following code only makes event tracking valid and turns off warnings:

<script id=debugdirectives Runat=server language=javascript>
@set @debug = False
@set @trace = False
@set @trace_events = True
</SCRIPT>

If you are using Microsoft Internet Explorer 4.x, setting any @trace option overrides the body tag, which invalidates the event bindings (binding) in the body tag and ignores the properties. This problem will not occur if you are using Internet Explorer 5.0.

Event joins of the following types do not work in Internet Explorer 4.0:

<body onload= "Initialize ()" >
To solve this limitation, a different binding mechanism should be adopted. If you are using Visual Basic, Scripting Edition (VBScript), you can use an implicit (implicit) binding

<script language= "VBScript" >
Function Window_onload ()
Initialize ()
End Function
</SCRIPT>

If you're using JavaScript, you can call a global script that assigns a function pointer to a Window object event with the following code:

<script language= "JavaScript" >
Window.onload = Initialize
</SCRIPT>

If the current body tag contains attributes, you should replace them in the script by setting the properties of the Document object. For example, if the body tag currently contains a property bgcolor= "#FFFF00", you can set it by using the following script. Use the techniques listed above to invoke this script when the document is first loaded.

<script language= "JavaScript" >
function Initialize () {
Document.bgcolor = "#FFFF00";
}
</SCRIPT>



Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.