在WebForm_OnSubmit之后调用自定义客户端验证功能吗? .网 [英] Call custom client side validation function after WebForm_OnSubmit? .NET
问题描述
.NET验证程序控件运行其javascript后,我想运行一个简单的JS函数. 我的onsubmit值是javascript:return WebForm_OnSubmit();,它似乎是自动生成的,我无法更改.
I want to run a simple JS function after my .NET validator controls run their javascript. My onsubmit value is javascript:return WebForm_OnSubmit();, which seems to be generated automatically and I can't change it.
我是正确的假设我需要在此字段中添加一个函数以使其正常工作吗?另外,我的表单正在更改字段后进行验证(不是一旦提交表单就进行验证),这很好,但是是否有设置soimewhere来启用/禁用该功能?
Am I right in assuming I need to just add a function in this field to get it to work? Also, my form is validating after a field has been changed (not once the form has been submitted), which is great, but is there a setting soimewhere to turn that on/off?
谢谢!
推荐答案
虽然我将为以后发布一个较晚的答案.
如果您的aspx页面是简单页面(没有ContentPage,所以没有MasterPage),则可以直接在标记上添加onsubmit函数:
Althought it is a late answer I will post for future.
If your aspx page is a simple page (no ContentPage, so no MasterPage) you can add onsubmit function directly on the markup:
<form ... onsubmit="return myCustomValidation();"... >
"WebForm_OnSubmit()"
将首先执行,然后如果验证通过,将执行"myCustomValidation()"
.
"WebForm_OnSubmit()"
will be executed first and then if validation is ok "myCustomValidation()"
will be executed.
如果您的aspx页面是ContentPage(因此具有MasterPage),则您无权访问标记以执行与以前相同的操作.您可以在后面的代码中将"myCustomValidation()"
设置为在"WebForm_OnSubmit()"
之后执行:
If your aspx page is a ContentPage (so it has a MasterPage) you don't have access to markup in order to do the same as before. You can set "myCustomValidation()"
to be executed after "WebForm_OnSubmit()"
in code behind:
Private Sub Page_PreRenderComplete(sender As Object, e As EventArgs) Handles Me.PreRenderComplete
If Not Page.ClientScript.IsOnSubmitStatementRegistered(Me.GetType, "aspxMyCustomValidation") Then
Page.ClientScript.RegisterOnSubmitStatement(Me.GetType, "aspxMyCustomValidation", "myCustomValidation()")
End If
End Sub
关键是在"PreRenderComplete"
事件中而不是在"Load"
事件中设置此代码,以便在"WebForm_OnSubmit()"
之后执行"myCustomValidation()"
.
The key is to set this code in "PreRenderComplete"
event and not in "Load"
event, in order to execute "myCustomValidation()"
after "WebForm_OnSubmit()"
.
这篇关于在WebForm_OnSubmit之后调用自定义客户端验证功能吗? .网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!