問(wèn)題描述
我只想在 Web 用戶控件中添加一些客戶端(JQuery Javascript)驗(yàn)證.我放置了一個(gè) OnClientClick 處理程序并調(diào)用了該函數(shù).但是,即使我返回false",OnClick 方法總是會(huì)被觸發(fā).我做錯(cuò)了什么?
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,目標(biāo)是使用 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.
這是一個(gè)示例代碼:
<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 事件中設(shè)置斷點(diǎn),我看到我進(jìn)入并且 btnAddSave_Click 事件也被執(zhí)行.
If I put a breakpoint in the Page_Load event, I see that I get in and the btnAddSave_Click event is also executed.
推薦答案
你有沒(méi)有返回 true
的點(diǎn)擊事件處理程序(通過(guò) jquery 注冊(cè))?在這種情況下,OnClientClick
的返回值將被忽略.
Do you have a click event handler (registered via jquery) which returns true
? In that case, the return value of OnClientClick
is ignored.
看看我的問(wèn)題(和答案):為什么 OnClientClick 不返回 false 取消回發(fā)
Have a look at my question (and answer): Why doesn't returning false from OnClientClick cancel the postback
這篇關(guān)于ASP.NET OnClientClick="return false;"不工作的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!