【问题标题】:ASP.NET Imagebutton Performs jQuery function after ValidationGroup ValidationASP.NET Imagebutton 在 ValidationGroup 验证后执行 jQuery 函数
【发布时间】:2013-08-28 01:38:44
【问题描述】:

在我的网络表单中同时使用 ASP.NET 和 jQuery 时遇到问题。

目前我有一个使用 ASP.NET 客户端验证的多 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()"/>

我还有一个 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>

问题是即使表单无效,jQuery 也会继续执行动画。无论如何我可以与jQuery交流吗?根据我的阅读,如果您有一个无效的字段,ASP.NET 验证器将导致 Page.Validate() 方法返回 false。我是否只需要转向 jQuery 验证?

【问题讨论】:

    标签: c# javascript jquery asp.net validation


    【解决方案1】:

    嗯,看来我刚刚找到了答案。这将适用于 ValidationGroup “UserInformation”

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

    【讨论】:

      【解决方案2】:

      您可以强制验证控件并更新其显示,如下所示:

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

      阅读ASP.NET Validation in Depth 了解有关客户端 API 和客户端对象的更多信息。

      【讨论】:

        【解决方案3】:

        使用 valid() 函数。

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

        【讨论】:

          猜你喜欢
          • 2010-12-02
          • 1970-01-01
          • 1970-01-01
          • 2012-02-20
          • 1970-01-01
          • 2021-03-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多