国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET中的無刷新驗證碼的開發(fā)(完整代碼)

2024-07-10 12:42:06
字體:
來源:轉載
供稿:網友
代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>無標題頁</title>
<script type="text/javascript">
function DoFresh() {
document.getElementById("Image1").src = "VerifyCode.aspx";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
驗證碼:<asp:TextBox ID="txtValidateCode" runat="server"></asp:TextBox>
</td>
<td>
<asp:Image ID="Image1" runat="server" />
<a href="javascript:DoFresh();">看不清?</a>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<br />
<asp:Literal ID="litErrorMsg" runat="server"></asp:Literal>
<asp:Button ID="btnSubmit" runat="server" Text="確定" onclick="btnSubmit_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Image1.ImageUrl = "VerifyCode.aspx";
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Session["ValidateCode"] != null)
{
string outputValidateCode = Session["ValidateCode"] as string;
string inputValidateCode = txtValidateCode.Text.Trim();
if (string.Compare(outputValidateCode, inputValidateCode, true) != 0)
{
//Response.Write("<script>javascript:alert('輸入的驗證碼錯誤!');</script>");
litErrorMsg.Text = "輸入的驗證碼錯誤!";
}
else
{
//Response.Write("<script>javascript:alert('輸入的驗證碼正確!');</script>");
litErrorMsg.Text = "輸入的驗證碼正確!";
}
}
}
#region 調用下面的方法實現(xiàn)客戶端保存Cookie驗證模式
private void ValidateMethod()
{
if (Request.Cookies["CheckCode"] == null)
{
litErrorMsg.Text = "您的瀏覽器設置已被禁用 Cookies,您必須設置瀏覽器允許使用 Cookies 選項后才能使用本系統(tǒng)。";
litErrorMsg.Visible = true;
return;
}
if (String.Compare(Request.Cookies["CheckCode"].Value, TextBox1.Text.ToString().Trim(), true) != 0)
{
litErrorMsg.Text = "<font color=red>對不起,驗證碼錯誤!</font>";
litErrorMsg.Visible = true;
return;
}
else
{
litErrorMsg.Text = "<font color=green>恭喜,驗證碼輸入正確!</font>";
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 蓝田县| 铜山县| 于田县| 自贡市| 冕宁县| 喜德县| 乐山市| 平果县| 台南县| 卢湾区| 新河县| 弥勒县| 行唐县| 德清县| 芜湖市| 靖宇县| 徐汇区| 星子县| 青岛市| 阳曲县| 剑阁县| 寻乌县| 望奎县| 澎湖县| 嘉荫县| 定结县| 肥东县| 安仁县| 东乡族自治县| 嘉定区| 云安县| 墨脱县| 观塘区| 新平| 富蕴县| 镇坪县| 应城市| 武强县| 石城县| 曲阜市| 内丘县|