validationmessage in captcha

May 6, 2013 at 2:08 AM
How can i add validationmessagefor to hold the error when text does not match?How can active clientvalidation on captcha so that client validation will perform before server validation.Please help me ,it is urgent.
Coordinator
May 6, 2013 at 9:59 AM
Hello again,
How can i add validationmessagefor to hold the error when text does not match?
You can create custom layout for captcha and add validationmessagefor like this:
@Html.ValidationMessage(Model.InputElementId)
How can active clientvalidation on captcha so that client validation will perform before server validation.
Do you want to check captcha using JavaScript?

Regards,
Vyacheslav Volkov
May 7, 2013 at 2:24 AM
Yes i want to check by java script.
Jul 3, 2014 at 12:48 PM
Edited Jul 3, 2014 at 2:18 PM
Hi. I had the same issue with custom Layout - the error message was shown in @Html.ValidationSummary, but never appeared in @Html.ValidationMessage(Model.InputElementId). My mistake was:
When passing custom data to captcha layout I was creating a new ViewDataDictionary and populating it with custom messages --> that way I was overwriting the existing ViewDataDictionary:
var captcha3 = Html.MathCaptcha("_Captcha", new ViewDataDictionary
{
         {"refreshButtonText", "Refresh"},
          ...
 }
Instead I had to pass new View Data while retaining the existing View Data (see the constructor overload):
var captcha3 = Html.MathCaptcha("_Captcha", new ViewDataDictionary(this.ViewData)  {
        {"refreshButtonText", "Refresh"},
        ...        
    }, null);