SimpleModal breaks ASP.Net Postbacks

前端 未结 10 1952
名媛妹妹
名媛妹妹 2020-12-08 20:00

I\'m using jQuery and SimpleModal in an ASP.Net project to make some nice dialogs for a web app. Unfortunately, any buttons in a modal dialog can no longer execute their po

10条回答
  •  情深已故
    2020-12-08 20:30

    I have found the following works without modifying simplemodal.js:

    function modalShow(dialog) {
    
        // if the user clicks "Save" in dialog
        dialog.data.find('#ButtonSave').click(function(ev) {
            ev.preventDefault();
    
            //Perfom validation                
    
            // close the dialog
            $.modal.close();
    
            //Fire the click event of the hidden button to cause a postback
            dialog.data.find('#ButtonSaveTask').click();
        });
    
        dialog.data.find("#ButtonCancel").click(function(ev) {
            ev.preventDefault();
            $.modal.close();
        });
    }          
    

    So instead of using the buttons in the dialog to cause the postback you prevent their submit and then find a hidden button in the form and call its click event.

提交回复
热议问题