19

I'm using a jquery UI dialog to modify a data row in a ASP.NET website, When opening the dialog I append the dialog to the underlaying form, this gives me the possibility of using postbacks. $('#' + id).parent().appendTo($("form"));

But when I set the dialog property modal: true Not just the background is grayed out, the dialog is also gray and inaccessible.

If I remove the $('#' + id).parent().appendTo($("form")); it works like supposed to but then i can't use postbacks.

Am I doing something wrong or do i miss a point to get this to work?

Javascript in top of .aspx

<script type="text/javascript">
    $(document).ready(function () {

        $('#workDialog').dialog({
            autoOpen: false,
            draggable: true,
            resizable: false,
            width: 800,
            height: "auto",
            modal: true
        });
    });

    function showDialog(id) {
        $('#' + id).parent().appendTo($("form"));
        $('#' + id).dialog("open");
    }

    function closeModalDiv(id) {
        $('#' + id).dialog("close");
    }
</script>

The div containing the dialog

<div id="workDialog" title="Basic dialog">
    <asp:UpdatePanel ID="upWorkDialog" runat="server" UpdateMode="Conditional">  <ContentTemplate>
        <table id="Table1" class="item">
        <tr>
            ...
        </tr>
        <tr>
            <td><asp:TextBox ID="txt...></asp:TextBox></td>
            <td><asp:TextBox ID="txt...></asp:TextBox></td>
            <td><asp:TextBox ID="txt...></asp:TextBox></td>
            <td><asp:TextBox ID="txt...></asp:TextBox></td>
        </tr>
        </table>
        <asp:Label ID="lblWorkEditError" runat="server" Text=""></asp:Label>

        <asp:Button ID="btnSave" runat="server" Text="Gem" OnClick="btnSave_Click" />
        <asp:Button ID="btnCancel" runat="server" Text="Annuller" OnClientClick="javascript:closeModalDiv('workDialog');" />
    </ContentTemplate></asp:UpdatePanel>
</div>
10
  • 1
    The Modal mask is z-indexed to cover the screen, thus anything you append to the form would be covered also. Commented Jan 31, 2013 at 17:49
  • Yes, but I have seen this done before with adding the dialog to the underlying form where the dialog is not grayed out. So it should work. Commented Jan 31, 2013 at 17:57
  • Can I raise the z-index for the dialog? and could that resolve the problem? Commented Jan 31, 2013 at 18:02
  • One true fact of code writing..... ANYTHING is possible. give it a try and see.... Happy coding:) Commented Jan 31, 2013 at 18:12
  • I have tried to give the dialog div a high z-index but no change at all Commented Jan 31, 2013 at 18:20

8 Answers 8

28

This is a known bug in 1.10.0 and works fine in older versions but I SOLVED it by changing the z-index for the ui-dialog style

add following style in your stylesheet or on page

.ui-dialog
{
    z-index: 101;
}

OR find .ui-dialog class in jquery-ui-1.10.0 css and add "z-index: 101;" style rule

now reload page and IT WORKS...

Sign up to request clarification or add additional context in comments.

2 Comments

Do you have a link to the bug?
You may to add the style rule in this way... .ui-dialog { z-index: 101 !important; }
6

This is a known bug in 1.10.0. I solved it by changing the z-index for the overlay.

$('#workDialog').dialog({
            modal: true,
            width: 400,
            height: 200,
            appendTo: $("form:first")
        });
        var dz = $(".ui-front").css("z-index")
        $(".ui-widget-overlay").css({ "z-index": dz - 1 });
        $(".ui-widget-overlay").appendTo($("form:first"));

3 Comments

Thanks for the answer @Karsten but unfortunately it does not work in my case. I have added your modifications and removed the $('#' + id).parent().appendTo($("form:first")); from the showDialog function, but the dialog is still gray when using 1.10.0
hmm. that's weird, it works just find for me even with 1.10.0.
Your answer seems to be the right solution, but when I can't make it work I have to go with Marcus answer for now. Thanks for the help
4

It's not allowed to move the dialog after it's been created. I think the easiest and best fix is to move the appendTo to the initialization of the dialog.

<script type="text/javascript">
$(document).ready(function () {

    $('#workDialog').dialog({
        autoOpen: false,
        draggable: true,
        resizable: false,
        width: 800,
        height: "auto",
        modal: true,
    appendTo: "#aspnetForm" // moved append to where the dialog i created
    });
});

function showDialog(id) {
    $('#' + id).dialog("open");
}

function closeModalDiv(id) {
    $('#' + id).dialog("close");
}
</script>

Comments

1

It looks like after version 1.10.0, the modal workaround doesn't work anymore. By downgrading the jQuery UI version to 1.9.2, it should work again.

Comments

0

I've tried and it should work. Could you try commenting out the line

 $('#' + id).parent().appendTo($("form"));

Modify where you initialize your dialog to take the object in a variable dlg2

var dlg2 = $("#dialog1").dialog({
    autoOpen: false,
    draggable: true,
    resizable: false,
    width: 800,
    height: "auto",
    modal: true,
    open: function (type, data) { $(this).parent().appendTo("form"); }
});

Add this line immediately after you initialize your dialog.

$(dlg2).parent().appendTo($("form"));

Do you have only one dialog? You could try initializing it in the dialog declaration adding the open code:

$("#dialog1").dialog({
    autoOpen: false,
    draggable: true,
    resizable: false,
    width: 800,
    height: "auto",
    modal: true,
    open: function (type, data) { $(this).parent().appendTo("form"); }
});

Link: jQuery UI Dialog with ASP.NET button postback

1 Comment

TT77 Yep I had already tried this and it appends the dialog to the form, it gave my the same result, As @Marcus pointed out there is something in version 1.10.0 that eliminates the workaround and downgrading seems to be the solution for the moment. But thanks for the help
0

The below code show fix your problem, worked for me:

<script type="text/javascript">
    $(document).ready(function () {

        $('#workDialog').dialog({
            autoOpen: false,
            draggable: true,
            resizable: false,
            width: 800,
            height: "auto",
            modal: true,
            appendTo: "form"
        });
    });

    function showDialog(id) {
        $('#' + id).dialog("open");
    }

    function closeModalDiv(id) {
        $('#' + id).dialog("close");
    }
</script>

In jQuery UI v1.10 they added an appendTo property, which seems to do the same thing as calling .parent().appendTo($("form")). The dialog appears on top of the grayed background. And Post back does work.

1 Comment

Isn't that the answer from orjan above? You should give him the credit.
0

on the second line in the showDialog function, add a css set for z-index. Should look like this:

function showDialog(id) {
    $('#' + id).parent().appendTo($("form"));
    $('#' + id).dialog("open").css({"z-index":"101"});
}

Comments

0

Karsten's answer worked for me with a minor tweak. I have to move $('#workDialog').dialog... after $(".ui-widget-overlay").appendTo($("form:first"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.