ASP 3.0 advanced programming (2)

Source: Internet
Author: User
Use the Form and QueryString collections
All values provided when you enter the <FORM> content on the page, or enter the value after the URL in the browser address bar, which are used by ASP scripts through the Form and QueryString collections. This is a simple way to access values in ASP code.
1. General techniques for accessing ASP collections
Most ASP sets are similar to common sets in VB. They are actually an array of values, but they can be accessed by using a text string key (not sensitive to size) and an integer index. Therefore, assume that the client Web page contains the following <FORM>:
<Form action = "show_request.asp" METHOD = "POST">
FirstName: <input type = "TEXT" NAME = "FirstName">
LastName: <input type = "TEXT" NAME = "LastName">
<Input type = "SUBMIT" VALUE = "Send">
</FORM>
You can access the values in the control by accessing the Form set of ASP:
StrFirstName = Request. Form ("FirstName ")
StrLastName = Request. Form ("LastName ")
You can also use the integer index of the control in the form. The index range starts from the control defined in the first HTML, and is sorted according to the defined order:
StrFirstName = Request. Form (1)
StrLastName = Request. Form (2)
However, the following integer-based indexing technology is not recommended, because once a control in HTML changes or a new control is inserted, then the ASP code will get the wrong value. Further, it is very confusing for people who read the code.
1) access all values of the set
The reference set can be used to convert a series of values on the entire Form into a single character variable without providing keys or indexes.
StrAllFormContent = Request. Form
If the text box contains values Priscilla and Descartes, the Request. Form statement returns the following characters:
FirstName = Priscilla & LastName = Descartes
Note that the provided values appear in the form of name/value pairs (that is, the control name = control value ), and each pair of names/values is separated by the symbol. This technique is useful if you want to pass the content in the form separately and want to get the value in the standard format of executable applications or DLL. However, in general, the content in the set is accessed by using the control name in the form as the text key.
2) traverse an ASP set
You can traverse all the members in an ASP set in two ways, which is basically the same as that of a common VB set. Each set provides a Count attribute and returns the number of entries in the set. You can use the Count attribute to traverse an integer index.
For intLoop = 1 To Request. Form. Count
Response. Write Request. Form (intLoop) & "<BR>"

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.