I'm trying to trigger the click event from a LinkButton with Jquery but it's not working.
I have 2 controls
<asp:TextBox ID="txtCoupon" runat="server" onkeyup="EnterEvent(event, this);"></asp:TextBox>
<asp:LinkButton ID="lnkValidateCoupon" runat="server" OnClick="lnkValidateCoupon_Click">Validate Coupon</asp:LinkButton>
And my js function
<script type="text/javascript">
function EnterEvent(e, ctrl) {
var keycode = (e.keyCode ? e.keyCode : e.which);
if (keycode === 13) {
$('[id$=lnkValidateCoupon]').click();
}
else {
return false;
}
}
</script>
When I do a Enter Key inside the textbox, it does nothing. I debugged with F12 with Chrome. I enter into the section click() but it does not trigger the server code of click event.
Wrap the controls in an asp:Panel
and set the DefaultButton
.
<asp:Panel runat="server" DefaultButton="lnkValidateCoupon">
<asp:TextBox ID="txtCoupon" runat="server"></asp:TextBox>
<asp:LinkButton ID="lnkValidateCoupon" runat="server" OnClick="lnkValidateCoupon_Click">Validate Coupon</asp:LinkButton>
</asp:Panel>