使用C#中的刷新按钮演示示例的验证码 [英] Captcha code with refresh button demo example in C#

查看:104
本文介绍了使用C#中的刷新按钮演示示例的验证码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







i想要带有刷新按钮的验证码...刷新按钮应该与更新面板配合使用只有验证码图像将部分改变.....我在网上搜索但刷新按钮只能用完全回发.....实际上我想在部分回发.....





并且不使用dll .......







请帮帮我

Hi,


i want captcha code with refresh button...refresh button should work with update panel so that only the captcha image will change partially.....i searched in net but refresh button will work with full postback only.....actually here i want in partial postback.....


and no use of dll.......



please help me

推荐答案

这个CodeProject文章,例如:简单的CAPTCHA,用C#创建你自己的 [ ^ ]。



< dd> -SA
This CodeProject article, for example: Simple CAPTCHA, Create your own in C#[^].

—SA


在Page_Load





protected void Page_Load(object发件人,EventArgs e)

{

位图obj = n ew System.Drawing.Bitmap(150,50);

Graphics objGraphics = System.Drawing.Graphics.FromImage(obj);

objGraphics.Clear(Color.LightGray) ;

objGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;



字体objFont = new字体(Arial,25,FontStyle.Italic | FontStyle.Strikeout);







随机r =新随机();

int startIndex = r.Next(1,5);

int length = r.Next(4,7);



String randomStr = Guid.NewGuid()。ToString()。Replace( - ,0)。Substring(startIndex,length);



Session。添加(randomStr,randomStr);





objGraphics.DrawString(randomStr,objFont,Brushes.DodgerBlue,5,5);





Response.ContentType =image / GIF;

obj.Save(Response.OutputStream, ImageFormat.Gif);



objFont.Dispose();

objGraphics.Dispose();

objBMP .Dispose();

}



和其他页面



TAke One Button,图像控制和一个文本框

pu以下代码在图像控制下



img height =30alt =Captchasrc =Test.aspxstyle =width:99px/>



将此代码置于按钮下方点击



protected void Button1_Click(对象发送者,EventArgs e)

{



if(TextBox1.Text.ToString()== Session [" randomStr"]。ToString())

{

Label1.Text =" Your Form已提交;

}

else

{

Label1.Text ="请输入正确的输入 ;

}

txtTest.Text = string.Empty;

txtTest.Focus();



}
In Page_Load


protected void Page_Load(object sender, EventArgs e)
{
Bitmap obj = new System.Drawing.Bitmap(150, 50);
Graphics objGraphics = System.Drawing.Graphics.FromImage(obj);
objGraphics.Clear(Color.LightGray);
objGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

Font objFont = new Font("Arial", 25, FontStyle.Italic | FontStyle.Strikeout);



Random r = new Random();
int startIndex = r.Next(1, 5);
int length = r.Next(4, 7);

String randomStr = Guid.NewGuid().ToString().Replace("-", "0").Substring(startIndex, length);

Session.Add("randomStr", randomStr);


objGraphics.DrawString(randomStr, objFont, Brushes.DodgerBlue, 5, 5);


Response.ContentType = "image/GIF";
obj.Save(Response.OutputStream, ImageFormat.Gif);

objFont.Dispose();
objGraphics.Dispose();
objBMP.Dispose();
}

And in other Page

TAke One Button, Image Control And one textbox
pu this below code under image control

img height="30" alt="Captcha" src="Test.aspx" style="width: 99px" />

put this below code under button click

protected void Button1_Click(object sender, EventArgs e)
{

if (TextBox1.Text.ToString() == Session["randomStr"].ToString())
{
Label1.Text = "Your Form is submitted";
}
else
{
Label1.Text = "Please enter input correctly";
}
txtTest.Text = string.Empty;
txtTest.Focus();

}


这篇关于使用C#中的刷新按钮演示示例的验证码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆