简体   繁体   English

如何在Page_load上强制进行页面验证

[英]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(); 但是当我运行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. 您可以尝试从javascript进行验证。 Take a look at this Force Page Validation from Javascript 看看Java中的强制页面验证

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. 如果您在Page_Load中调用上述方法(Page.Validate),则验证器将进行验证(如果此时它们存在于控件集合中)。 Are you dealing with dynamic controls. 您在处理动态控件吗? This may require a slightly different approach. 这可能需要稍微不同的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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