![](/img/trans.png)
[英]calling javascript function on OnClientClick event of a Submit button
[英]JavaScript OnClientClick breaking RadGrid Insert/Update button Submit behavior on web form
我有一個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的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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.