Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim code As String = GenerateVCodeImage() Session("VCode") = code End Sub |
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="btnCheck" runat="server" Text="Check It" /> <asp:Label ID="lblMessage" runat="server"></asp:Label><br /> <br /> <asp:Image ID="Image1" runat="server" Height="32px" Width="104px" ImageUrl=''VCode.aspx'' /> <br /> <br /> |
Protected Sub btnCheck_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCheck.Click Dim code As String = Session("VCODE") If TextBox1.Text.Trim.ToUpper = code Then lblMessage.Text = "校验成功!" lblMessage.ForeColor = Color.Blue Else lblMessage.Text = "您输入的注册码错误!" lblMessage.ForeColor = Color.Red End If TextBox1.Text = "" End Sub |
Private Function generateVCode(ByVal CodeLength As Integer) As String Dim VCode As String = String.Empty Dim randObj As New Random() Dim c As Integer = 63 For i As Byte = 1 To CodeLength ''是否显示 数字:0, 因为数字0 与字母O 容易混淆 ''While (c = 63) '' c = randObj.Next(35) ''End While c = randObj.Next(35) If c >= 10 Then c += 7 End If c += 48 VCode += Chr(c) Next Return VCode End Function |