An ASP.NET button click event is not firing

后端 未结 3 1393
死守一世寂寞
死守一世寂寞 2020-12-18 15:40

I have a button within a div which is hidden by default as it is used as a modal popup by jQuery UI.

The click event handler for this button never gets called, yet i

相关标签:
3条回答
  • 2020-12-18 15:44

    The problem here is that jQuery-UI creates the dialog outside of the <form> element, so clicking on it never submits the form.

    To get around this, rather than create a click event manually, you can just move the dialog <div> back into the form. I did a quick search and the answer to this question already covers the issue.

    So you just need to make this change:

    <script>
         // increase the default animation speed to exaggerate the effect
         $.fx.speeds._default = 1000;
    
         $(function () {
            var dialog = $("#dialog").dialog({
                            autoOpen: false,
                            show: "blind",
                            hide: "explode"
                         });
    
            // Move the dialog back into the <form> element
            dialog.parent().appendTo(jQuery("form:first"));
    
            $("#opener").click(function () {
               $("#dialog").dialog("open");
               return false;
            });
         });
    </script>
    
    0 讨论(0)
  • 2020-12-18 15:53

    A turnaround will be to change your button event to a client event, then trigger the server side event from client side.

    See Stack Overflow question How to fire a button click event from JavaScript in ASP.NET.

    0 讨论(0)
  • 2020-12-18 15:59

    Beware that this has ramifications when using a iFrame in your dialog. Moving a div with a iFrame in it causes that iFrame to post twice or more. If you have implemented this, I would check to see if this is true in your case. I have posted a work-around that I found here: https://stackoverflow.com/a/24663205/3334255

    0 讨论(0)
提交回复
热议问题