0

I have successfully added the Recaptcha dll reference using Nuget Package manager in Visual Studio 2012.

How can I add this in to the web part control? I have added a simple label in to my project. How can I add my Recaptcha control as below?

Label validationLabel = new Label();
this.Controls.Add(validationLabel);
Tommy
  • 38,021
  • 8
  • 85
  • 116
SPKan
  • 495
  • 2
  • 9
  • 24

1 Answers1

2

The details on how to use a Recaptcha control are on the Recaptcha Documentation.

Basically, this is how you do it:

Add this to the top of the page:

<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

Then use the control in your webpart like this:

<recaptcha:RecaptchaControl
    ID="recaptcha"
    runat="server"
    PublicKey="your_public_key"
    PrivateKey="your_private_key"
    />

To place this control on the WebPart from the .cs file, you can do something like:

protected void Page_Load(object sender, EventArgs e)
{
    if (this.IsPostBack)
        return;

    RecaptchaControl rc = new RecaptchaControl { PublicKey = "6LcvP...", PrivateKey = "6LcvP..." };
    this.Controls.Add(rc);
}

Since Sharepoint WebParts are ASP.NET controls, you can dynamically add controls as you wish. Handling them on PostBack could be a bit of a bother, but there's a lot of resources on this subject all over the net, including on this site. You should go through the Recaptcha documentation to see all the properties you can use.

Community
  • 1
  • 1
Taylan Aydinli
  • 4,130
  • 15
  • 36
  • 32
  • thanks for d answer.im using recaptcha dll in nuget manager. i need to insert in to a .cs file not to the markup file.i need to use using statement and add the control to the .cs page since im adding a web part. – SPKan Nov 13 '13 at 17:20
  • I added some more information to my answer. Check it out, see if it helps. – Taylan Aydinli Nov 14 '13 at 07:17