开发者

jquery submit form not calling button click event at server side

i am using asp.net and following code to submit form on enter key press it is working but only refreshing same page and not calling but开发者_如何转开发ton click event in server side code and without saving data it is comming back to same form, even without the jquery code again same thing happening don't know why but in some forms enter key press working fine and saving data without even following jquery code.

$(function() {
    $("form input").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
        alert('Alert is Working but data is not being Save Only Refresh');
            $('button[type=submit].default').click();
            return false;
        } else {
            return true;
        }
    });
});


This may be because the web protocol (HTTP) is stateless...it does not save the state of the objects on page when page is refreshed...pressing enter in your case only refreshes the page and hence the data is not getting saved. Try calling the button click event out-side the key-press function. It should then save your data.

Try this.. $('form').submit(function () {return false;}); make sure you put ur button tag inside form tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜