Reputation: 149
I have generated two alert messages(Captcha Success & Captcha failed) using
Page.RegisterStartupScript.
this is my code
if (recaptcha.IsValid)
{
Page.RegisterStartupScript("captcha", "<script language='javascript'>alert('Captcha Success');</script>");
}
else
{
Page.RegisterStartupScript("captcha", "<script language='javascript'>alert('Captcha Failed');</script>");
}
now i want to submit my form only captcha success alert is shown.. how can i do that? can anyone help please?
Upvotes: 3
Views: 1232
Reputation: 4022
If you want to stop the user from submitting the form using client-side code, you can use something like this:
if (recaptcha.IsValid)
{
Page.RegisterStartupScript("captcha", "<script language='javascript'>alert('Captcha Success');</script>");
}
else
{
Page.RegisterStartupScript("captcha",
"<script language='javascript'>" +
"function disableSubmitButton() {" +
"document.getElementById('***submitButtonID***').onclick = function(){return false;}" +
"}" +
"if(window.addEventListener) {" +
" window.addEventListener('load',disableSubmitButton,false);" +
"} else {" +
" window.attachEvent('onload',disableSubmitButton);" +
"}" +
"alert('Captcha Failed');" +
"</script>");
}
Note: Remember to replace ***submitButtonID***
with the ID attribute of the submit button.
You can also (more easily) control the button server-side if you don't want to disable it using JavaScript.
Upvotes: 1
Reputation: 118
Write your code inside the if(recaptcha.IsValid) following the pop up script.
Upvotes: 1