經常在論壇裡看到有問怎麼實現驗證碼的帖子
言歸正傳
首先
把數據存儲在Session中:Session(
從Session取值:dim testvalue as string=Session(
類似的:
把數據存儲在ViewState中:ViewState(
從ViewState中取值:dim testvalue as string=ViewState(
關於ViewState的更詳細的資料
百聞不如一見
gif
ValidateCode
下面給出gif
<%@ import namespace=
<%@ import namespace=
<%@ import namespace=
<%@ import namespace=
<script language=
Sub Page_Load(Sender as object
dim VNum as string=RndNum(
Session(
ValidateCode(VNum)
End Sub
Sub ValidateCode(VNum)
Dim Img as System
Dim g as Graphics
Dim ms as MemoryStream
dim gheight as integer=Int(Len(VNum)*
img=new BitMap(Gheight
g=Graphics
g
ms=New MemoryStream()
img
Response
Response
Response
g
img
Response
End Sub
Function RndNum(VcodeNum)
dim Vchar as string=
dim VcArray() as string=split(Vchar
dim VNum as string=
dim i as byte
For i=
Randomize
VNum=VNum & VcArray(Int(
Next
Return VNum
End Function
</script>
那麼又應該如何使用該文件生成的圖象驗證碼
<asp:Image id=
這就是用來顯示驗證碼的Image控件
<script language=
Sub Page_Load(Sender as object
dim VNum as string=Session(
Session
ViewState(
End Sub
Sub btnSubmit_click(sender as object
If txtValidateCode
lblShow
Else
lblShow
End If
End Sub
</script>
<html>
<body>
<form runat=
<div align=
<table width=
<!
<tr>
<td width=
<td width=
<td width=
<td width=
<td width=
<td width=
<td width=
</tr>
<tr>
<td height=
<td></td>
<td colspan=
<td> </td>
<td> </td>
</tr>
<tr>
<td height=
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height=
<td colspan=
<td valign=
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height=
<td colspan=
<td valign=
<td colspan=
<td> </td>
</tr>
<tr>
<td height=
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height=
<td> </td>
<td> </td>
<td valign=
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
</form>
</body>
</html>
From:http://tw.wingwit.com/Article/program/net/201311/13865.html