JavaScript OnClient点击破坏RadGrid插入/更新按钮在web表单上提交行为

JavaScript OnClientClick breaking RadGrid Insert/Update button Submit behavior on web form

本文关键字:web 按钮 表单 提交 更新 OnClient 插入 RadGrid JavaScript      更新时间:2023-09-26

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

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

感谢您的帮助。

好的,我把事情解决了。我相信这次中断是由Telerik的雷达控制更新引起的。

将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;
                }
            }