佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > asp.net ajax實現(xiàn)無刷新驗證碼

asp.net ajax實現(xiàn)無刷新驗證碼

熱門標簽:電子圍欄 團購網(wǎng)站 服務器配置 科大訊飛語音識別系統(tǒng) Mysql連接數(shù)設置 Linux服務器 銀行業(yè)務 阿里云
1、首先是在后臺驗證碼的aspx文件的Page_Load中的事件代碼:
復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace 學生在線考試系統(tǒng)
{
public partial class AjaxAutoCode : System.Web.UI.Page
{
//驗證數(shù)字
public string authcode = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
#region 第一種產(chǎn)生驗證碼的方法
Random random = new Random();
authcode = random.Next(1111, 9999).ToString();
//構造圖片
Bitmap image = new Bitmap(authcode.Length * 12, 25);
//創(chuàng)建畫布
Graphics g = Graphics.FromImage(image);
try
{
g.Clear(Color.White);
for (int i = 0; i 25; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
//鏈接兩點的線條
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
Font font = new Font("Arial", 12, FontStyle.Bold | FontStyle.Italic);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkBlue, 1.2f, true);
g.DrawString(authcode, font, brush, 2, 2);
//畫圖片的前景噪點
for (int i = 0; i 100; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
ms.WriteTo(this.Response.OutputStream);
ms.Close();
this.Response.ContentType = "image/gif";
}
finally
{
image.Dispose();
g.Dispose();
}
#endregion
}
}
}

2、其次在顯示驗證碼的頁面定義一個JS函數(shù)
復制代碼 代碼如下:

function fGetCode()
{
document.getElementById("getcode").src="Default2.aspx?"+Math.random();
}

3.再編輯前臺頁面aspx,下面是前臺頁面的代碼片段
復制代碼 代碼如下:

label>驗證碼/label>
asp:TextBox ID="txt_checkCode" runat="server" Width="178px">/asp:TextBox>
img src="Default2.aspx" alt="看不清楚?" id="getcode"/> a href="javascript:fGetCode()">更換驗證碼/a>
您可能感興趣的文章:
  • asp.net 驗證碼生成和刷新及驗證
  • ASP.net 驗證碼實現(xiàn)代碼(C#)
  • asp.net(C#) 生成隨機驗證碼的代碼
  • Asp.net(C#)實現(xiàn)驗證碼功能代碼
  • asp.net 簡單驗證碼驗證實現(xiàn)代碼
  • ASP.NET MVC驗證碼功能實現(xiàn)代碼
  • ASP.NET 實現(xiàn)驗證碼以及刷新驗證碼的小例子
  • ASP.NET中的無刷新驗證碼的開發(fā)(完整代碼)
  • asp.net 圖片驗證碼的HtmlHelper
  • ASP.NET生成驗證碼的方法

標簽:萍鄉(xiāng) 衡水 江蘇 廣元 棗莊 大理 衢州 蚌埠

巨人網(wǎng)絡通訊聲明:本文標題《asp.net ajax實現(xiàn)無刷新驗證碼》,本文關鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    桑日县| 类乌齐县| 广饶县| 闽侯县| 盖州市| 甘南县| 乳山市| 常宁市| 长沙县| 克东县| 商洛市| 汝城县| 沽源县| 留坝县| 长岛县| 碌曲县| 如皋市| 昭平县| 松桃| 辽阳县| 潮安县| 宝鸡市| 酉阳| 成安县| 保定市| 离岛区| 同仁县| 都兰县| 清新县| 湛江市| 梓潼县| 平原县| 安庆市| 甘德县| 渑池县| 松原市| 清河县| 泰顺县| 城口县| 纳雍县| 天峻县|