How do i ensure my asp.net validators fire before i call client side javascript
I have an asp.net application with basic CRUD functionality. On a page where i am capturing customer details i have several asp.net validators to required fields. I have attached a JS confirm box on the asp.net save button for the form. The trouble is that when the user leaves required开发者_JAVA技巧 fields unfilled and clicks the save button, the JS confirm box comes up, when the ok button is clicked, the save method is called successfully and only after this happened do the asp.net validators fire and display that required information has been left out.
How can i cause the validators to fire before the JS box pops up?
Call the JS function Page_ClientValidate()
it will return true/false whether or not the validators are all valid.
You would need to call the JS Box (confirm message, that is) after all the validations occur. That is, you need to call it from your code-behind. Like this:
Page.ClientScript.RegisterStartupScript(this.GetType(), "Confirm", "ConfirmMessage();", true);
where ConfirmMessage() is the Javascript function where you display the confirm message box.
精彩评论