如何使用C#读取ASP.NET中文本框中的验证码值 [英] How to read captcha value in textbox in ASP.NET with C#

查看:46
本文介绍了如何使用C#读取ASP.NET中文本框中的验证码值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在asp.net中使用验证码,c#工作正常,但问题是我在文本框中输入的值得知道的值必须存储在数据库中,图像中有5个字符,因为iam试图存储在数据库中它只存储一个字符

iam使用下面的代码,任何人都可以帮我获取所有字符





iam using captcha in asp.net with c# its working fine,but the problem is what ever captcha value i entered in text box that value i have to store in database, there are 5 characters in image as iam trying to store in database it is storing only one character
iam using this below code ,can anyone help me to get all characters

<pre><%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc1" %>







<table border="0" cellpadding="3" cellspacing="0">
<tr>
    <td colspan="3">
        Enter Text
        <asp:TextBox ID="txtCaptcha" runat="server"></asp:TextBox>
    </td>
</tr>
<tr>
    <td colspan="2">
        <cc1:CaptchaControl ID="Captcha1" runat="server" CaptchaBackgroundNoise="Low" CaptchaLength="5"
            CaptchaHeight="60" CaptchaWidth="200" CaptchaMinTimeout="5" CaptchaMaxTimeout="240"
            FontColor="#D20B0C" NoiseColor="#B1B1B1" />
    </td>
    <td>
        <asp:ImageButton ImageUrl="~/refresh.png" runat="server" CausesValidation="false" />
    </td>
</tr>
<tr>
    <td>
        <asp:CustomValidator ErrorMessage="Invalid. Please try again." OnServerValidate="ValidateCaptcha"
            runat="server" />
    </td>
    <td align="right">
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
    </td>
    <td>
    </td>
</tr>
</table>




protected void ValidateCaptcha(object sender, ServerValidateEventArgs e)
{
    Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());
    e.IsValid = Captcha1.UserValidated;
    if (e.IsValid)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Valid Captcha!');", true);
    }
}







任何身体都可以帮助我获得



我尝试了什么:



i也尝试了google serch,很多例子但我只能存储一个字符




can any body help me for getting

What I have tried:

i tried google serch as well,many examples but i can store only one character

推荐答案

我建​​议你在提交按钮点击事件中获取文本框值并存储在数据库中。
I suggest you to get the text box value in submit button click event and store in the database.


这篇关于如何使用C#读取ASP.NET中文本框中的验证码值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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