0
我的網頁Asp.net按鈕單擊事件處理程序執行時,兩次使用jQuery
<asp:TextBox Text="" ID="txtEmailOApodo" MaxLength="70" runat="server" Width="250px"
Style="height: 25px"></asp:TextBox>
<asp:TextBox Text="" ID="txtContrasena" MaxLength="50" TextMode="Password" runat="server"
CssClass="textoLightbox"></asp:TextBox>
<div style="margin-top: 20px">
<asp:UpdatePanel runat="server" ID="updPanelLoginIncorrecto">
<ContentTemplate>
<asp:CustomValidator ForeColor="Red" OnServerValidate="usuarioExistente_Validation"
Display="Static" Font-Size="Small" runat="server" ID="vldLogin" Text="<%$ Resources:LocalizedText, MsjError_LoginIncorrecto%>">
</asp:CustomValidator>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnLoginLightbox" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
<div class="tableContent" style="float: right;">
<asp:Button CssClass="button" ID="btnLoginLightbox" Text="Login" runat="server" OnClick="btnLoginUserControl_Click" />
</div>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#<%=txtContrasena.ClientID%>").keyup(function (event) {
if (event.keyCode == 13) {
$("#<%=btnLoginLightbox.ClientID%>").click();
}
});
$("#<%=txtEmailOApodo.ClientID%>").keyup(function (event) {
if (event.keyCode == 13) {
$("#<%=btnLoginLightbox.ClientID%>").click();
}
});
});
</script>
上輸入我有這個在後面的代碼我有
protected void btnLoginUserControl_Click(object sender, EventArgs e)
{
//Some code....
}
我不知道爲什麼當我關注txtContrasena或txtEmailOApodo並按下回車鍵時,btnLoginUserControl_Click會執行兩次。
我試着添加event.preventDefault或返回false;沒有工作:( – elvainch
的關鍵功能執行兩次。我用警報取代了click(),並且警報顯示兩次 – elvainch