Order of execution of ASP scripts

Source: Internet
Author: User
Tags variable

First let's take a look at the process of ASP page execution

1.IIS to find the ASP file, submitted to the ASP engine (generally ASP.DLL) processing.

2. The engine opens the ASP file to find the content between <% and%>, and of course <script runat= "Server" > and the corresponding </script> content, which is called the script block. Only the contents of the script block are parsed by the engine, and other content is inserted between the script blocks as meaningless characters. It is necessary to explain that there are more than these,<!--#include the server-side containing files of ***--> classes are also included and processed by the engine. If you read more programs, you will also know that some of the runat attributes labeled "Server" <object> objects will also be processed, without further discussion.

3. The engine executes the script in the script block, and the server-side scripts are executed as a whole, that is, you can write the following code:

<%
Dim i
For i=1 to 5
%> Hello World!
<% Next %>

The engine does not parse the script blocks separately, making the two script blocks syntactically incorrect. So we've come to the conclusion that not all non-server script code is sent to the client, and it is possible that the non-server script code is limited by the script block. The server is sure not to worry about the execution of the client script, but it can output different client script from the server-side script.

4. The final engine produces a text stream, or the execution result of the script, which can be considered a string, or code that is sent to the client browser's Web page. The client browser displays the page, at which point the source file contains no server-side script, but includes the results of the server-side script execution (which is obvious).

<% ...%> and <script runat= "Server" >...</script>

They are both server-side scripts that are processed and executed. They are executed as a whole.

<% ...%> and <script language= "..." >...</script>

The former is the server-side script, and the latter is the client script. The former executes first, the latter later.

In fact, the two scripts are likely to be executed at the same time, but the space is different, the former is performed on the server, the latter in the client browser. The former is logically bound to advance in the latter's execution. At the same time we concluded that client script could not be fed back to server-side scripts in the same page, that is, clients browsing your message book and submitting a new message or any of the values obtained by any client script could not be processed in the same server response.

About calls to components

Note Server-side scripts and client script are both scripts, and you can naturally create XMLHTTP components, ADODB. Connection components, but not anywhere.

XMLHTTP If the crawl Web page for the server (such as acquisition) is created in the server script, and if it is for the client Ajax without refreshing and backend access to the server side of the page, then it is running on the client, naturally in the client creation.

ADODB. The connection component is used to access the database, generally on the server side, after all, is the server-side ASP program running database data, but if your database is really connected at the client, then there is no doubt in the client script created.

In short, contradictory things and each side of each has its own characteristics. Different things have different contradictions, the same thing in the development of different processes and different stages have different contradictions, the same thing in different contradictions, the same contradictions in the two different aspects of each has its own particularity (can not understand the omission to see ...). )。 This principle requires us to adhere to the specific principles of concrete analysis, under the guidance of the principle of universality of contradictions, concretely analyze the particularity of contradictions, and find the correct way to solve the contradictions. Opposition to the use of a method to solve the contradictions of different things. "Key starts locks, to what mountain to sing what song" Is this truth.

Server-side VBScript script creation object using the Server.CreateObject (ClassName) method, the client VBScript script creates objects using the CreateObject (ClassName) method.

Typical error

<%
Function TSize(b)
'这是我自定义的函数
TSize="中国"
end function
%>
<a href="javascript:<%TSize('变量')%>" >点这里要使用我定义的函数</a>

Error Analysis:

Confusing server-side script with client script. In practice, we will find that the client does not receive anything like Tsize code, because the tsize is the server-side program, after the engine processing (note that the engine for the function of the processing, purely to server-side script calls, not sent back to the client) disappeared, it is not possible to function on the client This means that client script cannot directly invoke a function of a server-side script.

In fact, the program is grammatically incorrect, and the engine processes this content by first finding the content between <% and%>, the <%tsize (' variable ')%>, which obviously does not conform to VBScript's grammatical rules. Well, change to <%=tsize ("variable")%> the server-side script there is no syntax error, then the Tsize function can return the value of the normal "China", so the client received the HREF attribute is this: "JavaScript: China", is not executable.

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.