Andreas
Andreas

Reputation: 715

jQuery UI Dialog + ASP.NET user control

I'm looking for alternative ways of solving a problem. We're using ElFinder for browsing files, and we want to allow the user to change the access rights to a file element through the right-click context menu ("Change permissions"). The solution I have come up with so far is to load a server side ASP.NET usercontrol in a jQuery modal dialog window. This user control will contain the logic needed to add / remove user access to the selected element.

The jQuery Dialog script looks like this (slightly changed for readability), where DisplayItemAccessConfig() is the method that's called from the context menu:

<!-- access control script -->
<script type="text/javascript" charset="utf-8">

     function DisplayItemAccessConfig() {
        $.getJSON('AccessRights.ashx', function (data) {

            var itemName = data["itemName"];

            /* set new title (JUST FOR TESTING) */
            $(dialog).dialog('option', 'title', itemName);

            /* open modal dialog --> */
            $(dialog).dialog('open');

        });

    }

    $(function () {
        $("#dialog").dialog({
            autoOpen: false,
            modal: true,
            buttons: {
                "Ok": function () { $(this).dialog("close"); },
                "Cancel": function () { $(this).dialog("close"); }
            },
            open: function (type, data) {
                $(this).parent().appendTo("form");
            }
        });
    });    
</script>

Challenge 1: find a way to reload the user control each time the jQuery popup is displayed - this is to retrieve the current access settings for the selected element. Now it loads when the page is first loaded, since it's just a div element containing an update panel with a placeholder for my usercontrol and visibility set to none. Anyone have any tips here?

Challenge 2: While I am trying to figure that one out I thought it could be worth while asking for other opinions. Is there a better way of solving this? Should I use a pure jQuery with HTML and call server side .ashx methods to retrieve data, instead of an ASP.NET usercontrol?

Upvotes: 2

Views: 1819

Answers (1)

Stian
Stian

Reputation: 1299

  1. You can do this by creating a hidden button on inside the uploadpanel and then trigger it like this:

    __doPostBack('<%= Button.ClientID %>','');

  2. Personally I would drop the UpdatePanel and go for jQuery AJAX calls to update the content of the dialog window, but this depends on the complexity of your user control. Hard to say without seeing more of your code.

Upvotes: 1

Related Questions