jQuery UI Dialog with ASP.NET button postback

前端 未结 17 1841
鱼传尺愫
鱼传尺愫 2020-11-22 14:43

I have a jQuery UI Dialog working great on my ASP.NET page:

jQuery(function() {
    jQuery(\"#dialog\").dialog({
        draggable: true,
        resizable:          


        
相关标签:
17条回答
  • 2020-11-22 15:14

    This was the clearest solution for me

    var dlg2 = $('#dialog2').dialog({
            position: "center",
            autoOpen: false,
            width: 600,
            buttons: {
                "Ok": function() {
                    $(this).dialog("close");
                },
                "Cancel": function() {
                    $(this).dialog("close");
                }
            }
        });
    
    dlg2.parent().appendTo('form:first');
    $('#dialog_link2').click(function(){
        dlg2.dialog('open');
    

    All the content inside the dlg2 will be available to insert in your database. Don't forget to change the dialog variable to match yours.

    0 讨论(0)
  • 2020-11-22 15:15
    $('#divname').parent().appendTo($("form:first"));
    

    Using this code solved my problem and it worked in every browser, Internet Explorer 7, Firefox 3, and Google Chrome. I start to love jQuery... It's a cool framework.

    I have tested with partial render too, exactly what I was looking for. Great!

    <script type="text/javascript">
        function openModalDiv(divname) {
            $('#' + divname).dialog({ autoOpen: false, bgiframe: true, modal: true });
            $('#' + divname).dialog('open');
            $('#' + divname).parent().appendTo($("form:first"));
        }
    
        function closeModalDiv(divname) {
            $('#' + divname).dialog('close');
        }
    </script>
    ...
    ...
    <input id="Button1" type="button" value="Open 1" onclick="javascript:openModalDiv('Div1');" />
    ...
    ...
    <div id="Div1" title="Basic dialog" >
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <ContentTemplate>
              postback test<br />
              <asp:Button ID="but_OK" runat="server" Text="Send request" /><br />
              <asp:TextBox ID="tb_send" runat="server"></asp:TextBox><br />
              <asp:Label ID="lbl_result" runat="server" Text="prova" BackColor="#ff0000></asp:Label>
            </ContentTemplate>
        <asp:UpdatePanel>
        <input id="Button2" type="button" value="cancel" onclick="javascript:closeModalDiv('Div1');" />
    </div>
    
    0 讨论(0)
  • 2020-11-22 15:17

    The $('#dialog').parent().appendTo($("form:first")) solution works fine in IE 9. But in IE 8 it makes the dialog appear and disappear directly. You can't see this unless you place some alerts so it seems that the dialog never appears. I spend one morning finding a solution that works on both versions and the only solution that works on both versions 8 and 9 is:

    $(".ui-dialog").prependTo("form");
    

    Hope this helps others that are struggeling with the same issue

    0 讨论(0)
  • 2020-11-22 15:21

    You are close to the solution, just getting the wrong object. It should be like this:

    jQuery(function() {
        var dlg = jQuery("#dialog").dialog({
                             draggable: true,
                             resizable: true,
                             show: 'Transfer',
                             hide: 'Transfer',
                             width: 320,
                             autoOpen: false,
                             minHeight: 10,
                             minwidth: 10
                         });
        dlg.parent().appendTo(jQuery("form:first"));
    });
    
    0 讨论(0)
  • 2020-11-22 15:21

    Be aware that there is an additional setting in jQuery UI v1.10. There is an appendTo setting that has been added, to address the ASP.NET workaround you're using to re-add the element to the form.

    Try:

    $("#dialog").dialog({
         autoOpen: false,
         height: 280,
         width: 440,
         modal: true,
         **appendTo**:"form"
    });
    
    0 讨论(0)
  • 2020-11-22 15:22

    Primarily it's because jQuery moves the dialog outside of the form tags using the DOM. Move it back inside the form tags and it should work fine. You can see this by inspecting the element in Firefox.

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