17 ASP Programming Basics Typical Code

Source: Internet
Author: User

1.ASP method to obtain form input data: Get POST





A. Get: The client adds the data to the URL after the format is "? Field 1 = Enter data 1& Field 2 = Enter data 2&amp ... ", and then send it to the server. For example: Action is www.abc.com, field Name input data is Jack, field age data is 15, then use Get method for http://www.abc.com?Name=jack&Age=15





Two. Post: The client uses HTTP information data to transfer to the server  asp:  get: Use the 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 Fan For example: 〈a hery= "Aspform.asp?" Name=jack&age=15 ">  Press this 〈/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> asp1b.asp's content  <html><body> <% =request.querystring (" Input1 ")  %> hi, your character is <%= request.querystring (" Input2 ")  %> 





</body></html>





2.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 the request. From (name). Count Count: by request. The From (name). Count know the Name field to enter several values, without 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 will show * if it is not read by index. Available 〈% for each item request. From ("input")) Repomse.write Item & "<br>" Next%> also available 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%>





3. Methods for obtaining client TCP/IP ports, such as: TCP/IP port is <%=request ("Server_port")%> use Server_port to receive connection port information for HTTP request





4. 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%>





5. Now the date Time command is <%=now%> can





6.ASP Gets the form data input method by using a built-in object-requect, which varies get,post.





7. If you want to write your own VB or other language, the. dll file can be used by the ASP to register the DLL: dos input Regsbr32 *.dll





8. Display five repeating sentences, fonts getting larger <% for I=1 to 5%> <font size=<% =i%> color= #00ffff > Fast asp </font> <br> <% Next%>





9. Send string to client Response.Write string such as: <% Response.Write "Welcome"%>





10. 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.





11. Integration of other languages with asp: Good morning display, good afternoon <% if time>+ #12:00:00 am# and time< #12:00:00 PM # then greeting= "Good morning!" Else g reeting= "Hello!" "End If%> <%=greeting%>

An example of the application of
12.<script> tag in asp:





<html> <body> <% Call function1%> </body> </html> <script runat=server language= javascript> function function1 () {...} </script>





#include includes other documents <!--#include virtual|file= "filename"--> virtual refers to the fictitious file address. File represents an absolute filename address. such as: <!--#include virtual= "/booksamp/test.asp"--> <!--#include file= "/test/test.asp"-->





and can be nested in layers. In addition, #include cannot be
within <%--%>




14. Home Page Retention period if the client browser browses this home page within the period reserved for a home page, the original page content on the client's hard disk will be displayed. Response.expires[=number] Where 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 such as: you want to confirm that the user has seen the index.htm, you can check whether you have read, if not confirmed, then automatically connect to the home &lt;% if not session ("Been_to_home_page") Then Response.Redirect "index.asp" End If%&gt;





16. To determine whether to return to this page or first to enter &lt;% if User_has_been_here_before then Response.Write "&lt;h3 align=center&gt; Welcome back again "Else Response.Write" welcome! "End If%&gt;





17. Display a picture in a database with a super connection





&lt;% Set Conn=server.creatobject ("Adodb.connection")


Conn.Open "Myaddress"


Set Rs=conn.execute ("Select Name,tel,url,image from myaddress")


%&gt;


&lt;p&gt;&nbsp;&lt;tabel&gt;&nbsp;&lt;tr&gt;&nbsp;&lt;%&nbsp;for&nbsp;i=0&nbsp;to&nbsp;rs.fields.count-1&nbsp; %&gt;&nbsp;&lt;td&gt;&nbsp;&lt;b&gt;&nbsp;&lt;%=rs (i) .name&nbsp;%&gt;

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.