开发者

Stop Postback after using JQuery Dialog?

I have a JQuery Dialog that is opened when a button is clicked. The first time around, it should do a postback, but when the dialog closes and I click the refresh button of the broswer, it sends the data开发者_运维知识库 again and duplicates the data I just entered. Should I add a return false somewhere so it doesn't postback when the dialog is closed. Here is the script:

$(document).ready(function () {
    $('#showTerms').click(function () {
        $('#terms').dialog({
            closeOnEscape: false, modal: true, width: 650, height: 400, title: 'Create New Group'
        });
        $('#terms').dialog('open');
        $("#terms").parent().appendTo($("form:first"));
    });
});


If I understand what you're trying to do, try this...

Pass an event param into your click response function(...click(function(eventParam){...), then use that event param to cancel the default postback from the button with eventParam.preventDefault();.


You can prevent a button click postback, with some JS magic. Change the button to add UseSubmitBehavior="false" and OnClientClick="return false;" so that the default postback operation doesn't run when clicked.

Next, in the dialog handler, explicitly write the line when you want to postback on button click: __doPostBack('<%= btn.UniqueID %>', ''); which posts back to the server representing the button (though note, the second param, is the command name/arg appended together).

HTH.


You can prevent this by using the Post-Redirect-Get pattern.

The basic idea is that you never send users the results of POST requests, just GETs. That way, users never double submit, they can safely bookmark pages, and their browser history behaves predictably.

In your code-behind's handler for this method, simply redirect to the current page, making whatever changes you need to indicate the user accepted the terms.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜