OnClientClick and OnClick

First scenario: An asp button with no onclick event but only the onclientclick event. This event revoke a javascript function to start a timer and display the count down on the Div layer. Each time the button clicked, the whole web page gets refreshed, obviously even no OnClick event, it still post back.
“return false;” should applied after revoke onclientclick.

OnClientClick="setInterval('CountDown()',1000);return false;"
OnClientClick="return confirm('This OQP Session will be saved as verified. \n Are you sure?');"

Second scenario: In a web page submit process, the validation needs to be done before the submit, if failed to validate, then submit should not be triggered. However, no matter return false or ture after revoke the validation code, form still get submitted.

<asp:Button ID="SubmitBtn" runat="server" Text="submit"
OnClientClick="return txtcheck();"
OnClick="SubmitBtn_Click" />

function txtcheck()
   //username cannot be null
   var UserName = document.form1.txtUserName.value;
   if (UserName == ""){
             alert("Login cannot be null! ");
             return false;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s