19 Basic Tips for ASP

Source: Internet
Author: User
Tags count http request include client
Skill 1. Now the date Time command is
<%=now%> can

The 2.ASP method for obtaining data entry from a form is to use a built-in object (-requect).
It varies with get,post.

3. If you want to write your own VB or other language, the. dll file should be registered with the DLL for ASP: DOS
Enter Regsbr32 *.dll

4. Show five repeating sentences, fonts getting bigger
<% for I=1 to 5%>
<font size=<% =i%> color= #00ffff >
Fast ASP
</font>
<br>
<% Next%>

5. Send string to Client
Response.Write string
such as: <% Response.Write "Welcome"%>

6. Link to the specified URL address
Response.Redirect URL
Such as:
<% Response.Redirect "Homepage.asp"
%>

* But if this. The ASP's file content has been routed to the user, and then an error occurs when the redirect is used.

7. Integration of other languages with ASP:
Such as: Morning display, good afternoon show you
<%
If time>+ #12:00:00 am# and time< #12:00:00 PM #
Then
Greeting= "Good morning!"
Else
greeting= "Hello!"
End If
%>
<%=greeting%>

The application of 8.<script> tag in ASP
Cases:

<body>
<% Call Function1%>
</body>
<script Runat=server language=javascript>
function Function1 ()
{
...
}
</script>

9. #include including other documents
<!--#include virtual|file= "filename"-->
Virtual refers to a fictitious file address.
File represents an absolute filename address.
Such as:
<!--#include virtual= "/booksamp/test.asp"-->
<!--#include file= "/test/test.asp"-->

And you can nest layers. In addition, #include cannot be within <%--%>

10.ASP method to get form input data
: Get POST
A. Get: The client adds the data to the URL after the format is "? Field 1 = input data 1& field 2 = input data 2&amp ... ",
And then send it to the server.
For example: actiowww.abc.com, field name input data is Jack, field age data is 15, then use the Get method to
Http://www.abc.com?Name=jack&Age=15

Two. Post: The client uses HTTP information data to transfer to the server
In asp:
Get: Use "Enter data = request.querystring (field name)" To remove the data attached to the URL.
Post: Use the Enter data =request.forml (field name ")" to read the HTTP information data fields.
* Request.QueryString Example
such as: 〈a hery= "aspform.asp?" Name=jack&age=15 ">
Click here 〈/a〉〈p〉
Name:<%=request. QueryString ("Name")%)
Age:<%=request. Qeuerystring ("age")%)
* Get Example
aspturm.asp:
<form action= "asp1b.asp" method= "Get" >
Name: <input type=text name= "input1" value= "Your name" >
<p>
Features: <select name= "Input2" >
<option>cool!
<option>handsome
<option>warmhearted
</select>
<input type=submit value= "OK" >
</form>
The content of asp1b.asp
<% =request.querystring ("input1")%> Hi, your character is
<%= request.querystring ("Input2")%>
</body>11.request. From
Syntax: request. from (name) [(index) |. Count
Name: Field name
Index: When multiple values are entered in the same field, the pointer value index specifies the value to read the same field, ranging from 1 to
Request. From (name). Count
Count: By request. The From (name). Count knowable Name field enter several values, if no this name field, Count is 0


The following example:
<%
Fori=1 to Request.fron ("INPUT1"). Count
Response.Write Request. From ("Input1") (I) & "<br>"
Next
%>
If the INPUT1 has two values, it shows
* If the index is not used to specify which to read. Available
〈%
For each item request. From ("Input"))
Repomse.write Item & "<br>"
Next
%>
You can also use the for each x in Tewuest. From "repeatedly gets the input values for all fields.

<% for each x in request. Form%>
Request. From (<%=x%) =<%=request. Form
(x)%> <br>
<% Next%>


12.
To obtain the client TCP/IP Port method:
For example: TCP/IP port is <%=request ("Server_port")%>
Use Server_port to receive connection port information for HTTP request


13.
Using Http_accept_language HTTP header information, you can get the user-side language
Environment.
The following example determines the locale of the client and gives a different page.
<% language=request.servervariables ("Http_accept_language")
If language= "en" then%>
<!--#include file= "english.asp" >
<% Else%>
<!--#include file= "china.asp" >
<% End If%>

14. The duration of the homepage reservation
If the client browser browses this home page for the duration of a home page reservation, the original
The home page content on the user's hard disk will be displayed.
Response.expires[=number]
Number is the retention period for the Record Data box (PAGE box), in minutes.
Or:
Response.expiresabsolute[=[date][time]]
such as: Set a home page retention period to a certain date.

15. Connect to the specified URL address
If you want to confirm that the user has seen index.htm, you can check if you have seen it, such as
is not confirmed, automatically connects to the home page
<%
If not session ("Been_to_home_page") Then
Response.Redirect "Index.asp"
End If
%>

16. Whether to return to this page or the first time to enter
<%
If User_has_bee



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.