Reputation: 341
I have a button that is in a validation group and when any of the textboxes on the page are not filled in the onClick wont run like it is suppose to but the OnClientClick will run.
<asp:Button ID="btnSend" runat="server" Text="Send" ValidationGroup="send" OnClick="sendNow"
OnClientClick="document.getElementById('SendingMessage').style.visibility = 'visible'" />
Is there a way to stop the onclientclick from running like the onClick with the Validation group?
Upvotes: 0
Views: 1203
Reputation: 7591
onclick
is a server side event. onclientclick
is a client (javascript) action. In this case the button is clicked, therefore the onclientclick will execute. if the validation passes the browser will post to the form and the onclick
event will execute. If the validation fails then one of two things will happen depending on where the validation failed.
if the validation failed on the client then a request is never sent to the server. If the validation fails on the server than the form was posted to the server but the validation of the input failed and the onclick
event does not execute.
In your case you will want to add some client side code in the onclientclick
event that will validate the user's input. if the validation returns true, continue running the script. if the validation fails do not. There should be a way to tie into the webforms validation on the client. I'm not sure how to do it though.
Upvotes: 1