One CheckBox. one ImageButton. Why I can't force the user to click the agreement before submit form?

  • Thread starter Thread starter Benny Ng
  • Start date Start date
B

Benny Ng

Dear All,

<input type="checkbox" name="chkAgreement" value="0">I agree with the above
terms and conditions

<asp:ImageButton ID="ImgBtnSubmit" Runat="server" CausesValidation=True
ImageUrl="images/submit.gif" width="70" height="30"></asp:ImageButton>





There is one CheckBox and one ImageButton, Now the situation is , once I
click the ImageButton. The form submitted automatically.

But now my requirement is to force the user to click the agreement first.
And the submit the form.

Likes Hotmail. First to agree the agreement. And then submit. if not agree.
Then the form can't be action.

So, What can I do in here?

Thanks,

Benny Ng
 
Make sure ImageButton's Enabled property is set to false at the beginning.
Then set the AutoPostBack property of the checkbox to true and write
server-side code that once checkbox is checked, ImageButton is enabled. I
think this is a simple solution. Otherwise you may need to write some
CustomValidator implementation supporting both client and server side
interaction.
 
Add some javascript:

<scrip language="javascript">
<!--
function enablesubmit() {
if (document.getElementById("chkAgreement").checked == true)
{
document.getElementById("ImgBtnSubmit").disabled = false;
}else{
document.getElementById("btnActivate").disabled = true;
}
}
-->
</script>

Then add the following to the button:
<input type="checkbox" name="chkAgreement" value="0"
onclick="javascript:enablesubmit();">I agree with the above
terms and conditions

If your submit button is initially disabled then this should do what you
need, but it will save you a postback.

HTH
 
Dear Stuart Irving,

It's really working!!! It should be used "getElementById" function to
make the detection.

Thank you very much!

Benny Ng
 
Thank you very much, Kerem, OZMNA.

Benny Ng

Kerem OZMAN said:
Make sure ImageButton's Enabled property is set to false at the beginning.
Then set the AutoPostBack property of the checkbox to true and write
server-side code that once checkbox is checked, ImageButton is enabled. I
think this is a simple solution. Otherwise you may need to write some
CustomValidator implementation supporting both client and server side
interaction.
 
Back
Top