简体   繁体   中英

How to force page validation on Page_load

I have a situation where i need the validators to fire on a page when it is loaded. But when i run Page.Validate(); the validators are not fired. I here this is because you cant do validation this early. Is there away around this?

I think you cannot use Validate when page is loaded, it needs a postback. You can try to validate from javascript. Take a look at this Force Page Validation from Javascript

If you call the said method (Page.Validate) in Page_Load your validators will validate, if they exist in the control collection at this point. Are you dealing with dynamic controls. This may require a slightly different approach.

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