Change the asynchronous jQuery Dialog to be synchronous?

前端 未结 7 1372
名媛妹妹
名媛妹妹 2020-12-05 04:12

Currently, I\'m working to replace \"alert\'/\"confirm\" with the jquery dialog.

But most of legacy codes is written in some asynchronous way, which make it

相关标签:
7条回答
  • 2020-12-05 05:14

    To answer David Whiteman's more specific question, here's how I'm implementing a "deferred" postback for a LinkButton Click event. Basically, I'm just preventing the default behaviour and firing the postback manually when user feedback is available.

    function MyClientClickHandler(event, confirmationMessage, yesText, noText) {
        // My LinkButtons are created dynamically, so I compute the caller's ID
        var elementName = event.srcElement.id.replace(/_/g, '$');
        // I don't want the event to be fired immediately because I want to add a parameter based on user's input
        event.preventDefault();
        $('<p>' + confirmationMessage + '</p>').dialog({
            buttons: [
            {
                text: yesText,
                click: function () {
                    $(this).dialog("close");
                    // Now I'm ready to fire the postback
                    __doPostBack(elementName, 'Y');
                }
            },
            {
                text: noText,
                click: function () {
                    $(this).dialog("close");
                    // In my case, I need a postback when the user presses "no" as well
                    __doPostBack(elementName, 'N');
                }
            }
            ]
        });
    }
    
    0 讨论(0)
提交回复
热议问题