Using form and QueryString collections in ASP

Source: Internet
Author: User
Tags integer

The full value provided when the user fills out the page

content, or the value that is entered after the URL in the browser address bar, is used for ASP scripts through the FORM and QueryString collection. This is an easy way to access values in ASP code.

1, access to ASP collection of general technology

Most of the ASP sets are not much different from the common collections seen in VB. In fact, they are arrays of values, but can be accessed by using a text string key (insensitive to size) and an integer index. So, if the client Web page contains the following

:

<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 within the control by visiting the ASP's form collection:

strFirstName = Request.Form(“FirstName”)
strLastName = Request.Form(“LastName”)

You can also use the integer index of a control in a form, which starts with the first defined control in HTML and then sorts the order by definition:

strFirstName = Request.Form(1)
strLastName = Request.Form(2)

However, this type of integer-indexed technique is deprecated, because once a control in HTML has changed or a new control is inserted, the ASP code gets the wrong value. Further, it is very easy to confuse people who read the code.

1 access to the full value of the collection

You can use a reference collection to change a series of values on a form to a single character variable without providing a key or index.

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 supplied value is in the form of a name/value pair (that is, the control name = control value), and each pair of name/value is delimited by the symbol "&". This technique is useful if you intend to pass content from a form to an executable application or DLL in a standard format that you want to value. Generally, however, the contents of the collection are accessed by using the name of the control in the form as the text key.

2) traverse an ASP collection

There are two ways to traverse all members of an ASP collection in the same way as a common VB collection. Each collection provides a Count property that returns the number of entries in the collection. You can use the Count property to traverse by using an integer index.

For intLoop=1 To Request.Form.Count
Response.Write Request.Form(intLoop) & “<BR>”
Next

If the previous form contains two text boxes for Priscilla and Descartes values, you will get the following result:

Priscilla
Descartes

However, a better approach is to use the for each ... Next structure.

For Each objItem In Request.Form
Response.Write objItem & “=” & Request.Form(objItem) & “<BR>”
Next

The benefit is that you can access both the name of the control and its value. The above code will get the following results:

FirstName = Priscilla
LastName = Descartes

Note that some browsers may return to the ASP's

values in a different order than they appear on the 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.