我将 UpdatePanel 用于一些专门用于验证码的控件,因此,当 AsyncPostBack 由按钮“btnQuery”触发时,我如何告诉 .ashx(验证码处理程序)自行刷新它?
我使用会话将验证码上的图像验证为图像下方输入的 Num
这是处理程序:
<%@ WebHandler Language="C#" Class="captcha" %>
using System;
using System.Web;
using System.Web.SessionState;
using System.Drawing;
public class captcha : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/GIF";
Bitmap imagen_GIF = new System.Drawing.Bitmap(80, 30);
Graphics grafico = System.Drawing.Graphics.FromImage(imagen_GIF);
grafico.Clear(Color.Gainsboro);
Font tipo_fuente = new Font("Comic Sans", 12, FontStyle.Bold);
string randomNum = string.Empty;
Random autoRand = new Random();
for (int x = 0; x < 5; x++)
{
randomNum += System.Convert.ToInt32(autoRand.Next(0, 9)).ToString();
}
int i_letra = System.Convert.ToInt32(autoRand.Next(65, 90));
string letra = ((char)i_letra).ToString();
randomNum += letra;
context.Session["RandomNumero"] = randomNum;
grafico.DrawString(randomNum, tipo_fuente, Brushes.Black, 5, 5);
imagen_GIF.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
tipo_fuente.Dispose();
grafico.Dispose();
imagen_GIF.Dispose();
}
public bool IsReusable { get { return false; } }
}
我想刷新图像..不只是这样做:
public void postbackear()
{
string script = string.Format("Sys.WebForms.PageRequestManager.getInstance()._doPostBack('{0}', '');",
btnConsulta.ID);
ScriptManager.RegisterStartupScript(this.Page, typeof(string), "Refresh", script, true);
}