Is it connected to a form or just a standalone webpart?
You should be able to use this same code and hook it into your webpart.
Look at this control for an example:
<%@ Register Src="~/CMSFormControls/Captcha/SecurityCode.ascx" TagName="SecurityCode" TagPrefix="uc1" %>
<uc1:SecurityCode ID="captchaElem" runat="server" />
And make a property on your webpart called DisplayCaptcha
///
public bool DisplayCaptcha
{
get
{
return ValidationHelper.GetBoolean(GetValue("DisplayCaptcha"), false);
}
set
{
SetValue("DisplayCaptcha", value);
}
}
Then add this code to the setup control method
captchaElem.Visible = DisplayCaptcha;
lblCaptcha.Visible = DisplayCaptcha;
plcCaptcha.Visible = DisplayCaptcha;
And add this to the submit function:
// Check if captcha is required and verify captcha text
if (DisplayCaptcha && !captchaElem.IsValid())
{
// Display error message if captcha text is not valid
lblError.Visible = true;
lblError.Text = GetString("Webparts_Membership_RegistrationForm.captchaError");
return;
}
And that should be it...