我只想在 Web 用户控件中添加一些客户端(JQuery Javascript)验证.我放置了一个 OnClientClick 处理程序并调用了该函数.但是,即使我返回false",OnClick 方法总是会被触发.我做错了什么?
I just want to add some client side (JQuery Javascript) validation in a web user control. I put an OnClientClick handler and the function gets called. BUT, even if I return "false", the OnClick method always get fired. What am I doing wrong ?
我使用的是 VS 2010,目标是使用 JQuery 1.4.2 的 4.0 框架.和 JQuery UI 1.8.4.
I'm with VS 2010, targeting the 4.0 framework with JQuery 1.4.2. and JQuery UI 1.8.4.
这是一个示例代码:
<td style="text-align:right"><asp:Button ID="btnAddSave" OnClientClick="return ValidateMail();" OnClick="btnAddSave_Click" runat="server" Text="Submit" /></td>
脚本方法:
function ValidateMail() {
alert("Bouton clicked");
return false;
}
如果我在 Page_Load 事件中设置断点,我看到我进入并且 btnAddSave_Click 事件也被执行.
If I put a breakpoint in the Page_Load event, I see that I get in and the btnAddSave_Click event is also executed.
你有没有返回 true 的点击事件处理程序(通过 jquery 注册)?在这种情况下,OnClientClick 的返回值将被忽略.
Do you have a click event handler (registered via jquery) which returns true? In that case, the return value of OnClientClick is ignored.
看看我的问题(和答案):为什么 OnClientClick 不返回 false 取消回发
Have a look at my question (and answer): Why doesn't returning false from OnClientClick cancel the postback
这篇关于ASP.NET OnClientClick="return false;"不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Unity中图像的onClick事件onClick event for Image in Unity(Unity中图像的onClick事件)
运行总 C#Running Total C#(运行总 C#)
单击带有 JAvascript.ASP.NET C# 的超链接时删除目录Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(单击带有 JAvascript.ASP.NET C# 的超链接时删除目录)
asp.net listview 在单击时突出显示行asp.net listview highlight row on click(asp.net listview 在单击时突出显示行)
从函数调用按钮 OnClickCalling A Button OnClick from a function(从函数调用按钮 OnClick)
ASP.net C# Gridview ButtonField onclick 事件ASP.net C# Gridview ButtonField onclick event(ASP.net C# Gridview ButtonField onclick 事件)