SimpleModal breaks ASP.Net Postbacks

前端 未结 10 1962
名媛妹妹
名媛妹妹 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

    FWIW, I've updated the blog post you pointed to with come clarification, reposted here - the reasoning & other details are in the blog post:

    The solution (as of my last checkin before lunch):

    1. Override the dialog's onClose event, and do the following:
      1. Call the dialog's default Close function
      2. Set the dialog div's innerHTML to a single  
      3. Hijack __doPostBack, pointing it to a new function, newDoPostBack

    From some comments I’ve seen on the web, point 1 needs some clarification.  Unfortunately, I’m no longer with the same employer, and don’t have access to the code I used, but I’ll do what I can.  First off, you need to override the dialog’s onClose function by defining a new function, and pointing your dialog to it, like this:

    $('#myJQselector').modal({onClose: mynewClose});
    • Call the dialog's default Close function.  In the function you define, you should first call the default functionality (a best practice for just about anything you override usually):
    • Set the dialog div's innerHTML to a single   – This is not a required step, so skip it if you don’t understand this.
    • Hijack __doPostBack, pointing it to a new function, newDoPostBack
    function myNewClose (dialog)
    {
        dialog.close();
        __doPostBack = newDoPostBack;
    }
    1. Write the newDoPostBack function:
    function newDoPostBack(eventTarget, eventArgument)
    {
        var theForm = document.forms[0];
        if (!theForm)
        {
            theForm = document.aspnetForm;
        }
     
        if (!theForm.onsubmit || (theForm.onsubmit() != false))
        {
            document.getElementById("__EVENTTARGET").value = eventTarget;
            document.getElementById("__EVENTARGUMENT").value = eventArgument;
            theForm.submit();
        }
    }
        

提交回复
热议问题