简体   繁体   English

ASP.NET Imagebutton在ValidationGroup验证后执行jQuery功能

[英]ASP.NET Imagebutton Performs jQuery function after ValidationGroup Validation

I have an issue with using both ASP.NET and jQuery in my webform. 我在Webform中同时使用ASP.NET和jQuery时遇到问题。

Currently I have a multi-div registration that uses the ASP.NET clientside validation but I also want it to have jQuery animation to move from step to step. 目前,我有一个使用ASP.NET客户端验证的Multi-div注册,但我也希望它具有jQuery动画,可以逐步移动。

<asp:ImageButton ID="NextButton" runat="server" ImageUrl="images/registration/arrowright.png" Height="50px" onmouseover="this.src='images/registration/arrowrightgreen.png'"  onmouseout="this.src='images/registration/arrowright.png'" ValidationGroup="UserInformation" OnClientClick="onNextClick()"/>

I also have a jQuery function that moves to the next step of the registration. 我还有一个jQuery函数,可移至下一步注册。

<script type="text/javascript">
    $(document).ready(function () {
        $("[id$=pick_user_type]").hide();
    });

    function onNextClick() {
        $("[id$=registration_div]").hide('slide', { direction: 'left' }, 1000);
        $("[id$=pick_user_type]").show('slide', { direction: 'right' }, 1000);
    }
</script>

The issue is that jQuery will go ahead and do the animation even if the form is invalid. 问题是即使表单无效,jQuery也会继续进行动画处理。 Is there anyway that I can communicate to jQuery otherwise? 无论如何,否则我可以与jQuery通信吗? From what I have read, ASP.NET validators will cause the Page.Validate() method to returns false if you have an invalidated field. 根据我的阅读,如果您具有无效的字段,ASP.NET验证程序将导致Page.Validate()方法返回false。 Am I going to have to just move to jQuery validation? 我是否只需要转向jQuery验证?

Well, looks like I just found out an answer. 好吧,看来我刚刚找到了答案。 This will work on the ValidationGroup "UserInformation" 这将对ValidationGroup“ UserInformation”起作用

if (Page_ClientValidate("UserInformation")) {
    $("[id$=registration_div]").hide('slide', { direction: 'left' }, 1000);
    $("[id$=pick_user_type]").show('slide', { direction: 'right' }, 1000);
}

You can force the validation of a control and the update of its display, like this: 您可以强制控件的验证及其显示的更新,如下所示:

ValidatorValidate($('<%= myValidator.ClientID %>'));

Read ASP.NET Validation in Depth for more information about the client-side API and client-side objects. 有关详细信息,请阅读ASP.NET验证,有关客户端API和客户端对象。

use valid() function. 使用valid()函数。

if($("#form_id").valid()) 
{
  $("[id$=registration_div]").hide('slide', { direction: 'left' }, 1000);
  $("[id$=pick_user_type]").show('slide', { direction: 'right' }, 1000);
}

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

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