我有一个 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 中插入或更新数据。
感谢任何帮助。
最佳答案
好的,我已经解决问题了。我认为该中断是由 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;
}
}
关于c# - JavaScript OnClientClick 破坏 RadGrid 插入/更新按钮在 Web 表单上提交行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17617414/