0

我有两个 javascript 函数

1.

function ValidateGVEducation() {            

        var grid = document.getElementById('<%= gvEducation.ClientID %>');
        var ddlQuali, ddlUni, ddlInsti, ddlAreaS, ddlStat;

        //alert(grid.rows[1].cells[2].getElementsByTagName("*")[0].value);
        if (grid.rows.length > 0) {
            for (var i = 1; i < grid.rows.length; i++) {
                ddlQuali = grid.rows[i].cells[1].getElementsByTagName("*")[0];
                ddlUni = grid.rows[i].cells[2].getElementsByTagName("*")[0];
                ddlInsti = grid.rows[i].cells[3].getElementsByTagName("*")[0];
                ddlAreaS = grid.rows[i].cells[4].getElementsByTagName("*")[0];
                ddlStat = grid.rows[i].cells[6].getElementsByTagName("*")[0];
                if (ddlQuali.options[ddlQuali.selectedIndex].value != "0" ){
                    if (ddlUni.options[ddlUni.selectedIndex].value == "0" || ddlInsti.options[ddlInsti.selectedIndex].value == "0" || ddlAreaS.options[ddlAreaS.selectedIndex].value == "0" || ddlStat.options[ddlStat.selectedIndex].value == "0") {
                        alert('Fill Education Details');
                        return false;
                    }
                }

            }

            return true;
        }
        else return false;
    }

此函数在另一个函数中调用

   function validateControlsForSubmit(){
    if (ValidateGVEducation()) {
       alert('Fill Education Details');
       return false;
     }     
    return true;
   }  

稍后在保存按钮中调用函数。在显示警报后,后面的 aspx 代码正在执行..在这种情况下,返回 false 不起作用..

函数调用是

<asp:Button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Save" 
                     onclientclick="return validateControlsForSubmit();"  />

谢谢你。

4

1 回答 1

0

使用 jQuery:

<asp:Button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Save" />

$("#<%=btnSave.ClientID%>").on("click", function(event){
    if (ValidateGVEducation()) {
       alert('Fill Education Details');
      event.preventDefault();
     } 
});
于 2012-10-19T09:46:41.413 回答