Change the asynchronous jQuery Dialog to be synchronous?

前端 未结 7 1393
名媛妹妹
名媛妹妹 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();
        $('

    ' + confirmationMessage + '

    ').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'); } } ] }); }

提交回复
热议问题