jQuery Validation - Multiple submit buttons on one asp.net form, different validation groups?

前端 未结 6 1744
时光取名叫无心
时光取名叫无心 2020-12-07 06:01

I have an asp.net form with a login section and a register section. There are two submit buttons that correspond to the appropriate section, login or register. I am using

6条回答
  •  轮回少年
    2020-12-07 07:01

    You can always use some simple jquery/javascript to remove the "validate[required]" class on the asp button OnClientClick and then add it back on the other buttons OnClientClick which is easier than changing the validationengine files or replacing them. An example of this would be:

    The javascript would be:

    function disableReg() {
        $('#<%=txtName.ClientID%>').removeClass("validate[required]");
        $('#<%=txtEmail.ClientID%>').removeClass("validate[required]");
        $('#<%=txtUser.ClientID%>').addClass("validate[required]");
        $('#<%=txtPass.ClientID%>').addClass("validate[required]");
        return true;
    }
    
    function disableLogin() {
        $('#<%=txtUser.ClientID%>').removeClass("validate[required]");
        $('#<%=txtPass.ClientID%>').removeClass("validate[required]");
        $('#<%=txtName.ClientID%>').addClass("validate[required]");
        $('#<%=txtEmail.ClientID%>').addClass("validate[required]");
        return true;
    }
    

提交回复
热议问题