ASP。在调用Page_ClientValidate之后如何“重置”验证。

时间:2022-03-26 03:26:48

I have an ASP.NET page with a jQuery dialog that is displayed to change some data. I am setting up the jQuery dialog so that when the user clicks the OK button it calls ASP.NET's

我有一个ASP。使用一个jQuery对话框来改变一些数据。我正在设置jQuery对话框,以便当用户单击OK按钮时,它会调用ASP.NET

Page_ClientValidate('validationGroup') via javascript, finds all the invalid controls and changes their CSS class. So here's the scenario: the user opens the dialog, keys in some invalid data, clicks OK (receiving the validation messages), and then clicks Cancel.

Page_ClientValidate('validationGroup')通过javascript查找所有无效控件并更改其CSS类。这里是场景:用户打开对话框,在一些无效数据中键入密钥,单击OK(接收验证消息),然后单击Cancel。

Now the dialog is closed, but the validation messages are still there, so that when they open the dialog again, the data goes back to the way it was initially, but the form is still in the invalid state (the validation messages are still displaying).

现在对话框已经关闭,但是验证消息仍然在那里,所以当它们再次打开对话框时,数据会回到最初的状态,但是表单仍然处于无效状态(验证消息仍在显示)。

What I need is a "reset" function of sorts to call after calling Page_ClientValidate('validationGroup'). Does this exist?

我需要的是在调用Page_ClientValidate('validationGroup')之后调用的排序“reset”函数。这是否存在?

4 个解决方案

#1


1  

You can call the client-side function ValidatorValidate(validatorObj) to force validation to trigger again upon a specific validator. If you're resetting (clearing) the form values to what the validators are expecting as defaults, then triggering the ValidatorValidate function on them, you should be okay. See documentation here.

您可以调用客户端函数ValidatorValidate(validatorObj)来强制验证再次触发特定的验证器。如果您正在将窗体值重置(清除)到验证器预期的默认值,然后在它们上触发ValidatorValidate函数,那么您应该没有问题。在这里看到的文档。

#2


2  

Why don't you put the a from around the inputs in your dialog and use a reset button for cancel

你为什么不把a从你的对话框中输入,然后使用重置按钮来取消?

<input type="reset" value="Cancel" />

Edit:

编辑:

if your dialog control are already reset, re-validate when opening the dialog.

如果您的对话框控件已经重置,请在打开对话框时重新验证。

#3


1  

  1. Give your validators sequential IDs such as validator1, validator2, etc.

    给您的校验器序列id,例如校验器1、校验器2等等。

  2. Run the following javascript code to hide the error message:

    运行以下javascript代码来隐藏错误消息:

    var n = 0;
    var z = '';
    
    for (var i = 0; i < Page_Validators.length; i++) {
        n += 1;
        z = 'ctl00_MainContent_validator' + n;
        document.getElementById(z).style.visibility = 'hidden';
    }
    

    This will loop through your validators and hide any previously displayed error messages.

    这将循环遍历您的验证器,并隐藏任何先前显示的错误消息。

  3. When a submit button is pressed, the validators will do their thing again and display the error messages again for any validation which fails.

    当按下submit按钮时,验证器将再次执行它们的操作,并再次显示任何失败的验证的错误消息。

Voila.

瞧。

#4


0  

Why don't you just remove validation messages when user clicks cancel?

当用户单击cancel时,为什么不删除验证消息呢?

#1


1  

You can call the client-side function ValidatorValidate(validatorObj) to force validation to trigger again upon a specific validator. If you're resetting (clearing) the form values to what the validators are expecting as defaults, then triggering the ValidatorValidate function on them, you should be okay. See documentation here.

您可以调用客户端函数ValidatorValidate(validatorObj)来强制验证再次触发特定的验证器。如果您正在将窗体值重置(清除)到验证器预期的默认值,然后在它们上触发ValidatorValidate函数,那么您应该没有问题。在这里看到的文档。

#2


2  

Why don't you put the a from around the inputs in your dialog and use a reset button for cancel

你为什么不把a从你的对话框中输入,然后使用重置按钮来取消?

<input type="reset" value="Cancel" />

Edit:

编辑:

if your dialog control are already reset, re-validate when opening the dialog.

如果您的对话框控件已经重置,请在打开对话框时重新验证。

#3


1  

  1. Give your validators sequential IDs such as validator1, validator2, etc.

    给您的校验器序列id,例如校验器1、校验器2等等。

  2. Run the following javascript code to hide the error message:

    运行以下javascript代码来隐藏错误消息:

    var n = 0;
    var z = '';
    
    for (var i = 0; i < Page_Validators.length; i++) {
        n += 1;
        z = 'ctl00_MainContent_validator' + n;
        document.getElementById(z).style.visibility = 'hidden';
    }
    

    This will loop through your validators and hide any previously displayed error messages.

    这将循环遍历您的验证器,并隐藏任何先前显示的错误消息。

  3. When a submit button is pressed, the validators will do their thing again and display the error messages again for any validation which fails.

    当按下submit按钮时,验证器将再次执行它们的操作,并再次显示任何失败的验证的错误消息。

Voila.

瞧。

#4


0  

Why don't you just remove validation messages when user clicks cancel?

当用户单击cancel时,为什么不删除验证消息呢?