BÀI 4: XÂY DNG NG DNG ASP.
1. Các th HTML.
Cn xem li các tag HTML đặc bit là: FORM(name, method, action…),
INPUT(TEXT, BUTTON, SUBMIT…), CHECKBOX, RADIO, OPTION….
Mi th TAG HTML phi được xác định tên ca nó(name), giá tr ca
nó(value), và các thuc tính khác.
Ví d: <INPUT TYPE=TEXT NAME=T1 VALUE=TH READONLY>
2. Th FORM.
Trong mt trang có th có nhiu FORM, mi form xác định mt tp các hot động
ca nó, form phi được đặt 1 tên(name), trong mi form có th có nhiu đối tượng như
TEXTBOX, BUTTON, SUBMIT, OPTION……..
Mi form có phương thc(Method) chuyn d liu(nhn hay gi d liu nó bao
gm 2 phương thc GET hay POST), và phi xác định chuyn d liu đến đâu thông
qua ACTION, vì vy để khai báo Form thông thường chúng ta phi khai báo như sau:
<FORM NAME=formname METHOD=get/post ACTION=url>
Ví d:
Cho form sau gm Textbox có tên là T1
Để nhn li d liu ta có th s dng 1 trong 2 cách sau: Request.QueryString
hoc Request.Form.
* S dng Request.QueryString
Lnh Request.QueryString thường đi kèm vi form s dng phương thc GET
( method="get"). Thông tin gi t Form có phương thc GET s được hin th trên
thanh address bar ca trình duyt và nó b gii hn bi thong tin được gi(như s đối
s, giá tr d liu…).
<form name=lam method="get" action="simpleform.asp">
First Name: <input type="text" name="T1" />
<br />
<input type="submit" value="Submit" />
</form>
Nếu bn nhp giá tr cho T1 là DONGA thì trên thanh địa ch s hin th như sau:
Gi s ta có file ASP có tên "simpleform.asp" cha đon mã sau:
Kết qu hin th ra màn hình:
* S dng Request.Form
Câu lnh Request.Form dung để nhn giá tr t form vi phương thc GET( method="post"). Thông tin gi t form vi
phương thc POST s không b gii hn bi đối s và d liu.
If a user typed "Bill" and "Gates" in the form example above, the URL sent to the server would look like this:
Gi s file asp "simpleform.asp" cha đon mã sau:
Kết qu:
3. Th INPUT.
4. To vùng nhp liu.
5. To COMBO BOX.
Ví d 1: S dng Request.QueryString
<html>
<body>
<form action="demo_reqquery.asp" method="get">
http://maychu1/05TH1a/06th0010/simpleform.asp?T1=DONGA
<body>
Welcome:
<%
response.write(request.querystring("T1"))
%>
</body>
W
elcome DONGA
http://maychu1/05TH1a/06th0010/simpleform.asp
<body>
Welcome
<%
response.write(request.form("T1"))
%>
</body>
W
elcome DONGA
Your name: <input type="text" name="fname" size="20" />
<input type="submit" value="Submit" />
</form>
<%
dim fname
fname=Request.QueryString("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "!<br />")
Response.Write("How are you today?")
End If
%>
</body>
</html>
Ví d 2: S dng RADIO
<html>
<%
dim cars
cars=Request.Form("cars")
%>
<body>
<form action="demo_radiob.asp" method="post">
<p>Please select your favorite car:</p>
<input type="radio" name="cars"
<%if cars="Volvo" then Response.Write("checked")%>
value="Volvo">Volvo</input>
<br />
<input type="radio" name="cars"
<%if cars="Saab" then Response.Write("checked")%>
value="Saab">Saab</input>
<br />
<input type="radio" name="cars"
<%if cars="BMW" then Response.Write("checked")%>
value="BMW">BMW</input>
<br /><br />
<input type="submit" value="Submit" />
</form>
<%
if cars<>"" then
Response.Write("<p>Your favorite car is: " & cars & "</p>")
end if
%>
</body>
</html>