The method of implementing dynamic inclusion files using Execute in ASP _asp class classes

Source: Internet
Author: User
Absrtact: This paper introduces a method for ASP files to be dynamically included, and the ASP class (class) can be instantiated.

ASP, include file/virtual is handled by priority scripting code, so you cannot use include to dynamically include ASP files. We can use the Execute function to execute the required code dynamically.

Method:
Execute (ASP code)

Example: (vbCrLf for line breaks)
Copy Code code as follows:

Execute ("Class clsabc" &vbCrLf& "public Function output" &vbCrLf& "Response.Write 123" &vbCrLf& ' End Function ' &vbCrLf& ' End Class '


Copy Code code as follows:

Dim OBJABC
Set objabc = New clsabc
Objabc.output
Set objabc = Nothing

Can be used to read from a file or a database of ASP code to execute, note that the code executed should not contain <% and%>
Note Don't confuse with Server.Execute, Server.Execute parameter is ASP virtual path, and use this function not only cannot declare class class dynamically, not even can assign value to main program segment variable.
Example:
main.asp
Copy Code code as follows:

Dim STRABC,OBJABC
STRABC = "Test"
Server.Execute ("sub.asp")
Response.Write STRABC
Set objabc = New clsabc
Objabc.output
Set objabc = Nothing

sub.asp
Copy Code code as follows:

STRABC = "Execute"
Class CLSABC
Public Function output
Response.Write "Class"
End Function
End Class

After the main.asp is executed, only test is output, and OBJABC is not instantiated.

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.