ASP編程中18個基本技巧
來源:互聯網
上載者:User
編程|技巧 1. 現在的日期時間命令是<%=now%> 即可
2.ASP取得表格(from)資料輸入的方法,是使用一個內建的對象(object)—Requect,它以get,post而異。
3.若要自己用VB或其它語言編寫,.dll檔案供ASP使用需將DLL檔案註冊方可:DOS下輸入 regsbr32 *.dll
4.顯示五個重複的句子,字型越來越大
<% for i=1 to 5 %>
<font size=<% =i %> color=#00ffff>
ALLASP
</font>
<br>
<% next %>
5.傳送字串到使用者端
response.write string
如:<% response.write "Welcome" %>
6.連結到指定的URL地址
response.redirect url
如:
<% response.redirect "homepage.asp"
%>
*但是如果此.ASP的檔案內容已經傳送到使用者斷,則再用redirect時會發生錯誤。
7.其他語言與ASP的結合:
如:早上顯示早安,下午顯示你好
<%
if time>+#12:00:00 AM# and time<#12:00:00 PM #
then
greeting="早安!"
else
greeting="你好!"
end if
%>
<%=greeting %>
8.<script>標記在ASP中的應用
例:
<html>
<body>
<% call function1 %>
</body>
</html>
<script runat=server language=javascript>
function function1()
{
...
}
</script>
9.#include 包括其它檔案
<!--#include virtual|file="filename"-->
virtual指虛擬檔案地址。
file 代表絕對的檔案地址。
如:
<!--#include virtual="/booksamp/test.asp"-->
<!--#include file="/test/test.asp"-->
而且可以層層嵌套。另外#include 不能在<%--%>之內
10.ASP取得表格輸入資料的方法
:GET POST
一.get:使用者端將資料加到URL後,格式為”?欄位1=輸入資料1&欄位2=輸入資料2&...",
再將其送到伺服器。
如: action為www.abc.com, 欄位Name輸入資料為jack,欄位age的資料為15,則用get方法為
http://www.abc.com?Name=jack&Age=15
二.post:使用者端用http資訊資料傳送到伺服器
ASP中:
get:使用“輸入資料= Request.QueryString("欄位名")",將附加於URL的資料取出。
post:使用“輸入資料=Request.Forml"(欄位名")",讀取HTTP資訊資料欄位。
* Request.QueryString範例
如:〈A hery="aspform.asp?Name=jack&Age=15">
按此〈/A〉〈p〉
Name:<%=request.QueryString("Name")%)
Age:<%=request.QeueryString("Age")%)
* get 範例
·aspturm.asp:
<form action="asp1b.asp" method="get">