1

我有一个 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 中插入或更新数据。

任何帮助表示赞赏。

4

1 回答 1

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;
                }
            }
于 2013-07-12T19:53:50.763 回答