protected void refreshimgbtn_Click(object sender, ImageClickEventArgs e)
{
Page.MaintainScrollPositionOnPostBack = true;
txt_captch.Text = null;
captcha.ImageUrl = "~/CaptchaHandler.ashx?r=" + DateTime.Now.Ticks.ToString();
SetCaptchaText();
txtuserName.Focus();
}
private void SetCaptchaText()
{
try
{
Random oRandom = new Random();
string RndCaptcha = string.Empty;
char c;
for (int i = 0; i < 6; i++)
{
while (!Regex.IsMatch((c = Convert.ToChar(oRandom.Next(48, 128))).ToString(), "[1234567890]")) ;
RndCaptcha += c;
}
if (Session["Captcha"] == null)
{
Session["Captcha"] = RndCaptcha.ToString();
}
else
{
Session["Captcha"] = RndCaptcha.ToString();
}
}
catch (Exception ee)
{
ExceptionHandler.WriteException(ee.Message);
}
finally
{
}
}
if (string.IsNullOrWhiteSpace(txt_captch.Text) && txt_captch.Text.Length < 1)
{
LuminiousAlert.JavaScript.Alert("Enter Captcha !!");
}
else
{
if (Convert.ToString(Session["Captcha"]).Equals(SecureString(txt_captch.Text.Trim())))
{
}
else
{
// LuminiousAlert.JavaScript.Alert("Captcha code not found !!");
ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Invalid Captcha !!');", true);
Clear();
}
}
private void Clear()
{
txt_captch.Text = string.Empty;
}
---------------------------- ASPX page code
<fieldset>
<%-- <asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>--%>
<label>Enter Captcha</label>
<table width="100%">
<tr>
<td>
<asp:Image ID="captcha" runat="server" />
</td>
<td>
<asp:TextBox ID="txt_captch" CssClass="wpcf7-text width30" autocomplete="off" placeholder="Captcha" runat="server" />
<asp:ImageButton ID="refreshimgbtn" runat="server" Width="30" novalidate=''
style="vertical-align:bottom;" Height="30"
ImageUrl="~/images/refreshcaptcha.png" onclick="refreshimgbtn_Click" />
</td>
</tr>
<tr>
<td align="right">
</td>
<td align="center" >
<asp:Button ID="btnLogin" UseSubmitBehavior="true" AccessKey="" CssClass="wpcf7-submit" Text="Login" runat="server"
onclick="btnLogin_Click" />
</td>
<td align="left">
</td>
</tr>
</table>
<%-- </ContentTemplate>
</asp:UpdatePanel>--%>
</fieldset>
-----------------------
No comments:
Post a Comment