简体   繁体   中英

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 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?

调用JS函数Page_ClientValidate() ,无论验证程序是否全部有效,它都将返回true / false。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM