当 ASP.net 验证摘要已填写时,如何调用 javascript 函数
我的页面中有一个validationSummary。我想在validationSummary填充后调用一个javascript函数。我怎样才能做到这一点?
我认为我应该在后面的代码中添加一个属性,但我无法弄清楚该属性的键是什么。
有什么帮助吗?
i have a validationSummary in my page. i want to call a javascript function after the validationSummary is filled. how can i achieve this?
i think i should add an attribute in the code behind, but i can't figure out what is the attribute's key.
any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要调用 JavaScript 函数
Page_ClientValidate()
来启动连接到页面控件的 ASP.NET 验证。调用此函数后,Page_IsValid
布尔值将被正确设置。这是我如何使用它的示例。如果 ASP.NET 验证成功,我将禁用该按钮,否则该按钮保持启用状态并向用户显示验证摘要。
OnClientClick
来自 ASP:Button 控件。You will want to call the javascript function
Page_ClientValidate()
to initiate the ASP.NET validation wired to your page controls. Once this is called, thePage_IsValid
boolean value will be properly set.Here is an example of how I am using it. If ASP.NET validation is successful, I disable the button, otherwise the button remains enabled and the validation summary is displayed to the user. The
OnClientClick
is from a ASP:Button control.我认为这是不可能的。但是,可以通过在执行回发的控件上设置
OnClientClick
来拦截验证。然后您可以检查全局 JavaScript 变量Page_IsValid
来获取验证结果。需要记住的一件事是,当页面上没有验证器时,
Page_IsValid
将是未定义的。I don't think that's possible. It is, however, possible to intercept validation by setting
OnClientClick
on the controls that do postbacks. Then you can check the global JavaScript variablePage_IsValid
for the validation result.One thing to keep in mind is that, when there are no validators on a page,
Page_IsValid
will be undefined.我开始通过 @EverettEvola 实现该解决方案,但也多次调用验证逻辑并显示多个 ValidationSummary 弹出窗口。我的解决方案如下:
在按钮上(在我的例子中,按钮是提交按钮)
和 CustomValidationOnClick()
I started to implement the solution by @EverettEvola but also where the validation logic was being called multiple times and displaying multiple ValidationSummary popups. My solution was as follows:
On the button (in my case the button was a submit button)
And the CustomValidationOnClick()