Show and Hide in Code

NOTE: In this article, the Button widget is used to demonstrate how to show and hide the LoadPanel in code. This choice is made for purely demonstrational purposes, and you can do the same operations using another widget following the same guidelines.

To show or hide the LoadPanel in code, call the show() or hide() method. The same thing can be done using the toggle(showing) method. Pass true or false to this method to show or hide the LoadPanel, respectively.

jQuery

JavaScript
$(function() {
    $("#loadPanelContainer").dxLoadPanel({
        closeOnOutsideClick: true
    });

    $("#buttonContainer").dxButton({
        text: "Show the Load Panel", 
        onClick: function () {
            $("#loadPanelContainer").dxLoadPanel("show");
            // ---------- or ----------
            $("#loadPanelContainer").dxLoadPanel("toggle", true);
        } 
    });
});

ASP.NET MVC Wrappers

@(Html.DevExtreme().LoadPanel()
    .ID("loadPanel")
    .CloseOnOutsideClick(true)
)

@(Html.DevExtreme().Button()
    .ID("button")
    .Text("Show the Load Panel")
    .OnClick(@<text>
        function () {
            $("#loadPanel").dxLoadPanel("show");
            // ---------- or ----------
            $("#loadPanel").dxLoadPanel("toggle", true);
        } 
    </text>)
)

With AngularJS or Knockout, use a different technique. Bind the visible property of the LoadPanel widget to a scope property (in AngularJS) or an observable variable (in Knockout). After that, change this scope property or observable variable, and the LoadPanel will appear or disappear.

AngularJS

HTML
<div ng-controller="DemoController">
    <div dx-load-panel="{
        closeOnOutsideClick: true,
        bindingOptions: {
            visible: 'isLoadPanelVisible'
        }
    }"></div>
    <div dx-button="{
        text: 'Show the Load Panel',
        onClick: showLoadPanel
    }"></div>
</div>
JavaScript
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function DemoController($scope) {
        $scope.isLoadPanelVisible = false;
        $scope.showLoadPanel = function () {
            $scope.isLoadPanelVisible = true;
        }
    });

Knockout

HTML
<div data-bind="dxLoadPanel: {
    closeOnOutsideClick: true,
    visible: isLoadPanelVisible
}"></div>
<div data-bind="dxButton: {
    text: 'Show the Load Panel',
    onClick: function (e) {
        e.model.isLoadPanelVisible(true);
    }
}"></div>
JavaScript
var viewModel = {
    isLoadPanelVisible: ko.observable(false)
};

ko.applyBindings(viewModel);

To execute certain commands before or after the LoadPanel is shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the widget, assign it to the corresponding onEventName option. For example, in the following code, a handler of the shown event is assigned to the onShown option. This handler hides the LoadPanel three seconds after it was shown.

JavaScript
$(function() {
    $("#loadPanelContainer").dxLoadPanel({
        onShown: function (e) {
            setTimeout(function () { 
                e.component.hide();          
            }, 3000);
        }
    });

    $("#buttonContainer").dxButton({
        text: "Show the Load Panel", 
        onClick: function () {
            $("#loadPanelContainer").dxLoadPanel("show");
        } 
    });
});

If you are going to change event handlers at runtime, or if you need to attach several handlers to a single event, subscribe to the events using the on(eventName, eventHandler) method.

JavaScript
var shownEventHandler1 = function (e) {
    // First handler of the "shown" event
};

var shownEventHandler2 = function (e) {
    // Second handler of the "shown" event
};

$("#loadPanelContainer").dxLoadPanel("instance")
    .on('shown', shownEventHandler1)
    .on('shown', shownEventHandler2);
See Also