Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Wednesday, November 13, 2013

Example of how to add captcha in Asp.net using C#

How to add captcha in Asp.net programming :



In this post we see How to add captcha in asp.net add captcha in Asp.net web site :As we know that the captcha use for check the access by the human.it is use to make retraction for accessing web site or web pages by the automatically by software. 
So we describe some simple steps :
Step 1: Make a new web site
asp.net programming
how to add capcha in Asp.net programming


         b.)Go to file menu and click,
         c.)Go to web application ->new web site 
asp.net programming

         d.) After opening window give the name of web site.
        e.) Download capcha dll from fallowing links. As you wish.

Download Dll file for Captcha

Step 2: Add dll file in to web site.
         a.)Go to Solution Explorer-> right click on web site name .
         b.)Make bin folder for  adding .ddl files and .cs files ;
         c.)again click on web site name and add reference of dll files .
step 3: make a web page   
a.)    Right click on web site name and add new item ->select web page ->the open
b.)    Now in this web page Wright given code 

asp.net programming
.

Code for .aspx page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div class="S_Contact">
        <h2 class="S_Heading">
            Chapcha Demo</h2>
        <div class="row">
            <label>
                <p>
                    Full Name*
                </p>
            </label>
            <asp:TextBox ID="txtFName" runat="server"></asp:TextBox>
        </div>
        <div class="row">
            <label>
                <p>
                    Applyed For*
                </p>
            </label>
            <asp:TextBox ID="txtApplicationFor" runat="server"></asp:TextBox>
        </div>
         <div class="row">
            <label>
                <p>
                    Email*
                </p>
            </label>
             <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            <asp:RegularExpressionValidator ID="regValidator" runat="server" ErrorMessage="Email is not vaild."
                ForeColor="Red" ControlToValidate="txtEmail" ValidationExpression="^\s*(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*\s*$"
                ValidationGroup="a" Font-Bold="True" Font-Size="10px">Email is not vaild.</asp:RegularExpressionValidator>
        </div>
        <div class="row">
            <label>
                <p>
                    Upload Resume*
                </p>
            </label>
            <asp:FileUpload ID="FLUpload" runat="server" />
        </div>
        <div class="row">
            <cc1:CaptchaControl ID="ccJoin" runat="server" CaptchaBackgroundNoise="none" CaptchaLength="5"
                CaptchaHeight="40" CaptchaWidth="150" CaptchaLineNoise="None" CaptchaMinTimeout="5"
                CaptchaMaxTimeout="140" FontColor="Red" Width="155px" />
            <asp:TextBox ID="txtCaptcha" runat="server"></asp:TextBox>
        </div>
        <div class="row">
            <asp:Button ID="btnSave" runat="server" class="S_Btn cursor" Style="margin-right: 10px;"
               Text="Submit" onclick="btnSave_Click"  /><%--ValidationGroup="a"--%>
        </div>
        <div class="row">
            <asp:Label ID="lblMsg" runat="server" Visible="False" ForeColor="Red" Font-Bold="true"
                Font-Size="12px"></asp:Label>
        </div>
    </div>
    </div>
    </form>
</body>
</html>

Code for aspx.cs page :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {

        ccJoin.ValidateCaptcha(txtCaptcha.Text);
        if (!ccJoin.UserValidated)
        {
            lblMsg.Visible = true;
            lblMsg.Text = "Invalid Text. Try Again!";
            return; //Inform user that his input was wrong ...
        }
        else
        {

        }
    }
}

Thank you ..


Other Asp.net related post :  




Dropdownlist Related Post: