captcha

2

Click here to load reader

Upload: salman-mushtaq

Post on 13-Apr-2017

62 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Captcha

Captcha Control by Salman Mushtaq

Web.config

<?xml version="1.0"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <connectionStrings> <add name="Practice" connectionString="Data Source=.;Initial Catalog=Practice;Integrated Security=True"/> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.5.1" /> <httpRuntime targetFramework="4.5.1" /> </system.web> </configuration>

Mainform.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Recaptcha; namespace ReCaptchaExample { public partial class MainForm : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { lblInsertMessage.Visible = false; } protected void btnInsert_Click(object sender, EventArgs e) { if (Page.IsValid) { string name = txtName.Text.ToString(); CaptchaDataContext dbContext = new CaptchaDataContext(); Captcha cap = new Captcha(); cap.Name = name; dbContext.Captchas.InsertOnSubmit(cap); dbContext.SubmitChanges(); lblInsertMessage.Visible = true; lblInsertMessage.Text = "Data Successfully entered"; } else

Page 2: Captcha

{ lblInsertMessage.Visible = true; lblInsertMessage.Text = "Invalid Captcha... Please re-enter."; } } } }

MainForm.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainForm.aspx.cs" Inherits="ReCaptchaExample.MainForm" %> <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="MainForm" runat="server"> <div> <asp:Table runat="server"> <asp:TableRow runat="server"> <asp:TableCell runat="server"><asp:Label runat="server" Text="Name:"></asp:Label></asp:TableCell> <asp:TableCell runat="server"><asp:TextBox runat="server" ID="txtName"></asp:TextBox></asp:TableCell> </asp:TableRow> <asp:TableRow runat="server"> <asp:TableCell runat="server"> <recaptcha:RecaptchaControl ID="recaptcha" runat="server" PublicKey="Here you enter your public key which you find on Google Recaptcha API’S" PrivateKey="Here you enter your private key" /> </asp:TableCell> </asp:TableRow> <asp:TableRow runat="server"> <asp:TableCell runat="server"><asp:Button runat="server" ID="btnInsert" OnClick="btnInsert_Click" Text="Insert Data" /></asp:TableCell> <asp:TableCell runat="server"><asp:Label runat="server" ID="lblInsertMessage" Text=""></asp:Label></asp:TableCell> </asp:TableRow> </asp:Table> </div> </form> </body> </html>