c# - JavaScript OnClientClick 破坏 RadGrid 插入/更新按钮在 Web 表单上提交行为

标签 c# javascript asp.net radgrid

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

相关文章:

来自派生类的 C# 方法作为基构造函数中的委托(delegate)

c# - 如何从 Visual Studio 编辑器检索文本以与 Roslyn SyntaxTree 一起使用?

javascript - jquery动画菜单: how to get active state

javascript - 用于 Javascript 的 Facebook SDK,FB.login() 回调未触发(异步调用永远不会得到响应?)

javascript - 设置输入类型文本格式而不更改值

c# - Kinect 裁剪图像

c# - 如何根据基于变量数组运行的 foreach 循环更新进度条?

Jquery-UI Thickbox 无法正常工作

asp.net - 我如何获取错误 500 的日志/调试?

c# - 在 Web 应用程序中使用条码渲染框架生成的条码下的条码编号