Skip to main content

How to add captcha to your website? (How to use Google reCAPTCHA?)

Automated applications (bots, robots) can perform brute force attacks to your contact forms or registration pages. These attacks may cause a leakage in confidential information as well as service outage.

The crucial approach to prevent automated applications to mess up with your web forms is that using captcha verification. There are several third party services to implement captcha in your website. I will briefly explain how to use Google’s service called Google reCAPTCHA.

How to use Google reCAPTCHA?

  1. Sign up and create a new record
  2. It will give you a SITE KEY and SECRET KEY. You will use these values below
  3. Add this line before the closing </head> tag in HTML page:
    <script src=''></script>
  4. Add this line where you want the reCAPTCHA widget to appear (Make sure to replace YOUR-SITE-KEY with your own site key):
    <div class="g-recaptcha" data-sitekey="YOUR-SITE-KEY"></div>
  5. Once user clicks the submit button in your page, make this AJAX call in your JavaScript function (Make sure to replace YOUR-SECRET-KEY with your own secret ):

    var captchaResult = grecaptcha.getResponse();
    var googleCallResult;
         type: "POST",
         url: "" + captchaResult,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         failure: function (response) {
    success: function (response) {
         // if googleCallResult equals "true", captcha verification
         // is successful. It equals "false" if verification fails
         googleCallResult = response.success;
    }).done(function () {
         // Do stuff with googleCallResult
  6. That’s all! By using the variable “googleCallResult“, you can build your logic in your page. This variable will have “true” if the captcha verification is successful.


Call a function as soon as  the user verifies captcha

  1. Add “data-callback” attribute to your div class (Make sure to replace YOUR-SITE-KEY with your own site key):
    <div class="g-recaptcha" data-sitekey="YOUR-SITE-KEY" data-callback='captchaSuccessful'></div>
  2. Add your JavaScript function. This function will be called once user verify the captcha
    function captchaSuccessful() {
         // Do stuff here


More info about Google reCAPTCHA:

How to fix “Declaration expected”, “Syntax error”, and “Statement cannot appear outside of a method” errors that appear in a non-sense way in Visual Studio

There might be several different reasons for the generic errors below to appear.

Declaration expected
Syntax error
Statement cannot appear outside of a method

In my case, Visual Studio IntelliSense seemed to be showing these errors in every single line in my code-behind (cs) pages. Including the Page declaration in the ASPX page.


Follow the steps below until you solve the issue. If a step solves the problem, you don’t have to continue with the next step.

  1. Make sure to specify default language in your web.config (<compilation defaultLanguage=”C#”>)
  2. Specify default language in the beginning of your ASPX files (<%@ Page Language=”C#” %>)
  3. Page declarative must be the first line in your ASPX files. There shouldn’t be any lines including comments before your Page declarative (<%@ Page … %>
  4. Exclude the file from the project. Compile. Include it back
  5. Restart Visual Studio and recompile your code


How to use Windows Continuum? (No display adapter or dock needed)

Share your Windows phone’s screen with your PC by following simple steps below.

You don’t need any display adapter or dock to connect to your PC. However, you will need them if you want to use your phone with your TV or monitor.

  1. In your PC, go to “Settings > System > Projecting to this PC“. Select “Available everywhere” or “Available everywhere on secure networks
  2. In your Windows Phone, open the application “Continuum“. Select “Wireless Adapter“. Click “Connect
  3. Select your PC
  4. In your PC, confirm the connection request
  5. You are all set! Enjoy!

More info: