Reputation: 4721
I have a form where I have many textboxes which are getting validated through Required field validator, But there is a captcha control also which is not getting validated. However I can validate it through javascript.
Here alert gets displayed when I click on 'OK' of alert message box. But I want this message to be displayed on button click simultaneously with other validations.
Please help. Thanks in Advance.
Upvotes: 0
Views: 822
Reputation: 2039
I think you want to display the "Please enter captcha text." as part of the ValidationSummary
control.
To do this, you just need to let the server-side know the captcha text. Do this:
Add another textbox, but keep it hidden with display:none
:
<asp:textbox id="txtCaptcha" runat="server" style="display:none;">
Modify your Javascript to copy the captcha value into the txtCaptcha
textbox:
<script type="text/javascript">
$(document).ready(function () {
$('#' +'<%=btnSend.ClientID %>').on('click', function (e) {
var captcha = $("input[name$=CaptchaControl1]").val();
$('#' + '<%=txtCaptcha.ClientID %>').val(captcha);
})
});
</script>
Create a RequiredValidator
for txtCaptcha
textbox:
<asp:RequiredFieldValidator ID="RequiredFieldValidatorForCaptcha" runat="server" ErrorMessage="Please enter captcha text." ControlToValidate="txtCaptcha" Display="None" ValidationGroup="VG"></asp:RequiredFieldValidator>
Upvotes: 1