views:

11

answers:

1

I have jQuery UI dialog with ASP.NET. I wrap a list of check boxes in the dialog. Since, it's an "Edit page", some of the checkboxes are already checked because the data fetched from datatbase when page is first loaded.

I have no problem when I click on the link to open dialog, and everything works as expected. However, if I don't click on the link to open dialog, those checkboxes values will not be picked up from code-behind when form is submitted back. I understand because jQuery UI dialog append "div" to HTML body outside of the "form" element when the page is loaded.

    //I'm trying to append dialog-dept to form on document ready like this but not yet working
     $("#dialog-dept").parent().appendTo($("form:first"));

How do I make jQuery UI dialog part of "form" tag required by ASP.NET page when page first loaded?

Because there are many other fields on the page not just those checkbox. Sometime, there might be no need to open dialog to select any checkbox.

The code below works well only if I click on the link to open the dialog.

 $(document).ready(function() {

        // Dialog Link
        $('#dialog_link_dept').click(function() {
            $('#dialog-dept').dialog('open');
            return false;
        });

        // Launch Dialog
        $('#dialog-dept').dialog({
            autoOpen: false,
            width: 700,
            modal: true,
            open: function(type, data) {
                $(this).parent().appendTo("form");
            }
        });

    });
</script>
+1  A: 

You can move it into the <form> immediately upon creation, even if it's autoOpen: false, like this:

    $('#dialog-dept').dialog({
        autoOpen: false,
        width: 700,
        modal: true
    }).parent().appendTo("form");
Nick Craver
Nick, thank for this suggestion. It works only if I have only one dialog to append to the form. I tried this with two dialogs I have, only values from one dialog get picked up, value from another dialog are not. I'm still looking into this issue. Any more suggestion....
Narazana
@Narazana - This code only acts upon one element...IDs are supposed to be uniue, if you have multiple `id="dialog-dept"` you need to switch to classes and use `class="dialog-dept"` and `.dialog-dept` as your selector.
Nick Craver
Yes, all IDs for DIV I have are unique. Ok, since this code can apply to only one ID, then I switch to using classes. Thanks alot.
Narazana