ASP 3.0 Advanced Programming (32)

Source: Internet
Author: User
Tags array contains reference servervariables client
Programming | Advanced 7.2.4 Client Script errors
So far, we have learned about the errors from the ASP. However, ASP is often used to create Web pages that contain client-side scripting. If the <SCRIPT> element that contains the client code is not set to the runat= "server" attribute, the ASP will not consider the server and transfer the Web page information to the client without change.
Therefore, if an ASP page is open and a browser error dialog box is displayed, you should not look for errors in the ASP program code on the server side. The browser does not see the ASP program code, so do not recognize any errors, if a dialog box appears on the client, then there must be an error in the client code.
1. Syntax error
If the client-side program code in the Web page has syntax errors, the browser will have a corresponding error when the script is downloaded to the client. The Web page stops executing, although the contents of the Web page can still be loaded normally (unless they are dynamically loaded by these client script code). The user will see a dialog box containing the error details, or a status bar message indicating that the page contains an error.
Modern browsers tend to hide the details of Web script errors and only display a small error icon on the status bar. In IE 4.0 and IE 5.0, the normal error dialog can be activated by setting the Advanced page of the Internet Options dialog box, as shown in Figure 7-14:

Figure 7-14 Advanced Page Setup screen
Client errors in the processing script code are similar to those on the server side, and are usually easier to download because you can often double-click the Web page directly from the server directory. The only difference is that some server interactions are done by client script, such as data binding with RDS or dynamic loading, without the need to get web pages to see the results in the browser.
2. Run time or semantic error
In client script, you can often encounter syntax errors, and you will often experience run-time or semantic errors. In fact, on the client side, this phenomenon is very common. Because the client cannot control the script's environment like the server side, it is not sure what the user is running on their machine, and in fact the server can only get a general picture from some components such as browser capabilities.
Therefore, scripting programs that use client objects or special versions of scripting languages and properties are likely to not work correctly. However, handling client errors and handling server-side errors is almost the same.
3. Client program code created on the server
A special exception to the "Client dialog for ASP error pages" rule (where there is an error) when the error occurs is to use ASP program code to dynamically create client program code on the server. For example, you might want to evaluate in an ASP, and then pass the data to the script code that runs on the client, perhaps the easiest way is to insert the data as a variable into the script code:
<%
' Get the ' name of my server from the ServerVariables collection
strservernameinasp = Request.ServerVariables ("SERVER_NAME")
%>

<script language= "JScript" runat= "CLIENT" >
<!--hide code from older browsers
var strservername = "<% = strservernameinasp%>";
...
Alert (' Server name is: ' + strservername);
...
Stop Hiding Code
-->
</SCRIPT>
On the client side, after the ASP processes this page, you will get the following:
<script language= "JScript" runat= "CLIENT" >
<!--hide code from older browsers
var strservername = "Wroxbox";
...
Alert (' Server name is: ' + strservername);
...
Stop Hiding Code
-->
</SCRIPT>
You can ignore the runat= "CLIENT" attribute, but adding this can make it clearer when viewing ASP pages that run code.
Thus, if you want to add data from a server-side database to an array of clients in a location, you can implement the following program:
<script language= "JScript" runat= "CLIENT" >
<!--hide code from older browsers
var arrbooks = new Array (a)//highest available index would be

<% ' Start of ASP processing
Intindex = 0
Do as {not in the end of some recordset}
Strtitle = {Get title to database record}
Response.Write "arrbooks[" & CInt (Intindex) & "] = '" _
& Strtitle & "';" & VbCrlf
Intindex = Intindex +1
{Move to next record in database}
Loop
...
Do something in the client with the "array of book titles"
...
Stop Hiding Code
-->
</SCRIPT>
The client code generated by this server-side ASP program code creates an array of title titles when the client runs. The resulting client-side scripting error is now in the browser's error dialog box. The reason for the error is that the Arrbooks-named array is created by JavaScript code when it is run on the client and can accept only 9 titles, while server-side code is likely to produce more than 9 titles, depending on the number of records in the source database. This is equivalent to the following client code:
<script language= "JScript" runat= "CLIENT" >
<!--hide code from older browsers
var arrbooks = new Array (a)//highest available index would be
Arrbooks[0] = ' Instant JavaScript ';
Arrbooks[1] = ' Professional ASP 3.0 programming ';
ARRBOOKS[2] = ' ADO 2.5 programmers Reference ';
...
etc
...
ARRBOOKS[9] = ' ASP techniques for webmasters ';
ARRBOOKS[10] = ' ASP programmers Reference '; <-Client-side error occurs here
ARRBOOKS[11] = ' ADSI CDO programming ';
ARRBOOKS[12] = ' Professional MTS and MSMQ programming ';
...
Do something in the client with the "array of book titles"
...
Stop Hiding Code
-->
</SCRIPT>
This page can work correctly only after it has been modified, either by increasing the size of the array or by controlling the number of records from the database.

7.3 Preventing errors
There are a number of different types of errors that can be seen and some sense of finding errors. The following will consider how to avoid introducing bugs into the program, although there is no guarantee that the program is written without errors, but there are a number of techniques outlined here

[1] [2] [3] [4] Next page



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.