jquery button click not firing asp.net button
I've got a .net button that has an href attribute value set to
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cp1$ucInvoiceSearch$btnSearch", "", true, "", "", false, true))
I've got a textbox that when I press enter I want it to fire this event. Doing the '开发者_运维百科Enter' event isn't an issue but I can't get the event on the href to fire using .click(). Here's my function so far:
$("[id*='tbInvNo']").keyup(function(event){
var $btn = $(".pnl-invoice-search");
if(event.keyCode == 13)
$btn.click();
});
I've got no idea how to get this to fire. Hope someone can help - jQuery and asp.net are driving me up the wall today! :(
With this code you can simulate the button click when the user clicks enter ANYWHERE, maybe it's better than your original plan. If not, you can adapt it to your needs :-)
$(document).keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(
"<%=yourBtn.ClientID.Replace('_','$') %>", '', true, '', '', false, true))
return false;
} else {
return true;
}
});
Instead of using href, use onclick="WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$cp1$ucInvoiceSearch$btnSearch", "", true, "", "", false, true)) " and use trigger("click") instead of click().
精彩评论