SimpleModal breaks ASP.Net Postbacks

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

    Web browsers will not POST any disabled or hidden form elements.

    So what's happening is:

    1. The user clicks on a button in your dialog.
    2. The button calls SimpleModal's close() method, hiding the dialog and the button
    3. The client POSTs the form (without the button's ID)
    4. The ASP.NET framework can't figure out which button was clicked
    5. Your server-side code doesn't get executed.

    The solution is to do whatever you need to do on the client (closing the dialog in this case) and then call __doPostback() yourself.

    For example (where "dlg" is the client-side SimpleModal dialog reference):

    btn.OnClientClick = string.Format("{0}; dlg.close();",
                            ClientScript.GetPostBackEventReference(btn, null));
    

    That should hide the dialog, submit the form, and call whatever server-side event you have for that button.

    @Dan

    All standard ASP.NET postbacks work by calling a __doPostBack javascript method on the page.

    asp:Buttons do not call __doPostback() because HTML input controls already submit the form.

提交回复
热议问题