JavaScript OnClientClick打破RadGrid插入/更新按钮在Web表单上提交行为

时间:2013-07-12 14:34:42

标签: c# javascript asp.net radgrid

我有一个RadGrid插入/编辑表单模板,其中我有一个提交/更新按钮。如果我没有引用任何JavaScript调用,则此按钮的提交行为将完美运行。但是,在插入OnClientClick时,它会中断按钮。这是ASP

<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Save" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' OnClientClick="return CheckWeight()" />

这是JavaScript:

function CheckWeight() {
                var currentGoalWeightTotal = $("[id$='CurrentGoalWeightTotal']").val();
                var weightInput = $("[name$='AG_Weight']").val();

                if (parseInt(weightInput) + parseInt(currentGoalWeightTotal) > 100) {
                    alert("Please make sure that your goal weight total does not exceed 100.");
                    return false;
                }                    
            }

我应该注意,即使提交功能中断,OnClientClick也会触发。我只是无法在RadGrid中插入或更新数据。

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

好的,我解决了问题。我相信休息是由Telerik Rad控件的更新引起的。

将ASP更改为:

<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Save" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' OnClientClick="if (!CheckWeight()) { return false;}" UseSubmitBehavior="false" />

将JavaScript更改为:

function CheckWeight() {
                var currentGoalWeightTotal = $("[id$='CurrentGoalWeightTotal']").val();
                var weightInput = $("[name$='AG_Weight']").val();

                if (parseInt(weightInput) + parseInt(currentGoalWeightTotal) > 100) {
                    alert("Please make sure that your goal weight total does not exceed 100.");
                    return false;
                } else {
                    return true;
                }
            }