Question

I have a RadGrid Insert/Edit Form template in which I have a Submit/Update button. This button's submit behavior works perfectly if I do not reference any JavaScript calls in it. However, upon inserting an OnClientClick, it breaks the button. Here is the ASP

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

Here is the 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;
                }                    
            }

I should note that, even though the Submit functionality breaks, the OnClientClick does fire. I just cannot insert or update data in the RadGrid.

Any help is appreciated.

Was it helpful?

Solution

Ok, I got things fixed. I believe that the break was caused by an update to Telerik's Rad controls.

Changed the ASP to this:

<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" />

Changed the JavaScript to this:

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;
                }
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top