How can I trigger Button's OnClick event from Javascript in an asp.net application which is using Callback?
I'm using Callback, on a as开发者_运维问答p.net webforms project. When clicked button, it is working great. However I have a textbox, when user press 'enter' it must trigger button. So I did it,
function search_enter(event) {
if (event.keyCode == 13) {
$("#search_button").click();
}
}
Yes, it triggers first javascript function of callbacks. But it is doing postback not callback :S
How can I fix this?
Update: I solve the problem, calling callback event at input's keyup event.
function search_enter(event) {
if ($('#search_textbox').val() == '')
return;
WebForm_DoCallback('__Page', Basla(), Istek, null, Hata, true)
}
<input id="search_textbox" onkeyup="search_enter(event)" type="text" />
But if I pressed enter, when cursor in input. It is doing postback. How can I fix this?
I found it. if textbox is in <form runat="server">
tag, It is doing postback, when pressed enter. I've removed form tags and it solved.
精彩评论