API
To show or hide the Popup programmatically, 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 Popup, respectively.
jQuery
$(function() { $("#popupContainer").dxPopup({ title: "Popup Title", contentTemplate: function () { return $("<p />").text("Popup content"); } }); $("#showButton").dxButton({ text: "Show the Popup", onClick: function () { $("#popupContainer").dxPopup("show"); // === or === $("#popupContainer").dxPopup("toggle", true); } }); $("#hideButton").dxButton({ text: "Hide the Popup", onClick: function () { $("#popupContainer").dxPopup("hide"); // === or === $("#popupContainer").dxPopup("toggle", false); } }); });
ASP.NET MVC Controls
@(Html.DevExtreme().Popup() .ID("popup") .Title("Popup Title") .ContentTemplate(@<text> <p>Popup content</p> </text>) ) @(Html.DevExtreme().Button() .ID("showButton") .Text("Show the Popup") .OnClick(@<text> function () { $("#popup").dxPopup("show"); // === or === $("#popup").dxPopup("toggle", true); } </text>) ) @(Html.DevExtreme().Button() .ID("hideButton") .Text("Hide the Popup") .OnClick(@<text> function () { $("#popup").dxPopup("hide"); // === or === $("#popup").dxPopup("toggle", false); } </text>) )
@Code Html.DevExtreme().Popup() _ .ID("popup") _ .Title("Popup Title") _ .ContentTemplate(Sub() @<text> <p>Popup content</p> </text> End Sub).Render() Html.DevExtreme().Button() _ .ID("showButton") _ .Text("Show the Popup") _ .OnClick("showButton_click").Render() Html.DevExtreme().Button() _ .ID("hideButton") _ .Text("Hide the Popup") _ .OnClick("hideButton_click").Render() End Code <script> function showButton_click() { $("#popup").dxPopup("show"); // === or === $("#popup").dxPopup("toggle", true); } function hideButton_click() { $("#popup").dxPopup("hide"); // === or === $("#popup").dxPopup("toggle", false); } </script>
With Angular, AngularJS or Knockout, use a different technique. Bind the visible property of the Popup widget to a component property (in Angular), a scope property (in AngularJS), or an observable variable (in Knockout). After that, change them, and the Popup will appear or disappear.
Angular
<dx-popup title="Popup Title" [(visible)]="isPopupVisible"> <div *dxTemplate="let data of 'content'"> <p>Popup content</p> </div> </dx-popup> <dx-button text="Show the Popup" (onClick)="isPopupVisible = true"> </dx-button> <dx-button text="Hide the Popup" (onClick)="isPopupVisible = false"> </dx-button>
import { DxPopupModule } from "devextreme-angular"; // ... export class AppComponent { isPopupVisible: boolean = false; } @NgModule({ imports: [ // ... DxPopupModule ], // ... })
AngularJS
<div ng-controller="DemoController"> <div dx-popup="{ title: 'Popup Title', bindingOptions: { visible: 'isPopupVisible' } }"> <p>Popup Content</p> </div> <div dx-button="{ text: 'Show the Popup', onClick: showPopup }"></div> <div dx-button="{ text: 'Hide the Popup', onClick: hidePopup }"></div> </div>
angular.module('DemoApp', ['dx']) .controller('DemoController', function DemoController($scope) { $scope.isPopupVisible = false; $scope.showPopup = function () { $scope.isPopupVisible = true; }; $scope.hidePopup = function () { $scope.isPopupVisible = false; }; });
Knockout
<div data-bind="dxPopup: { title: 'Popup Title', visible: isPopupVisible }"> <p>Popup Content</p> </div> <div data-bind="dxButton: { text: 'Show the Popup', onClick: function (e) { e.model.isPopupVisible(true); } }"></div> <div data-bind="dxButton: { text: 'Hide the Popup', onClick: function (e) { e.model.isPopupVisible(false); } }"></div>
var viewModel = { isPopupVisible: ko.observable(false) }; ko.applyBindings(viewModel);
User Interaction
The Popup can also be hidden when a user clicks outside it. To control this behavior of the Popup, use the closeOnOutsideClick option.
jQuery
$(function() { $("#popupContainer").dxPopup({ title: "Popup Title", visible: true, closeOnOutsideClick: true }); });
Angular
<dx-popup title="Popup Title" [(visible)]="isPopupVisible" [closeOnOutsideClick]="true"> </dx-popup>
import { DxPopupModule } from "devextreme-angular"; // ... export class AppComponent { isPopupVisible: boolean = true; } @NgModule({ imports: [ // ... DxPopupModule ], // ... })
Events
To execute certain commands before or after the Popup was 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 when you configure the widget.
jQuery
$(function () { $("#popupContainer").dxPopup({ // ... onShowing: function (e) { // Handler of the "showing" event }, onShown: function (e) { // Handler of the "shown" event }, onHiding: function (e) { // Handler of the "hiding" event }, onHidden: function (e) { // Handler of the "hidden" event } }); });
Angular
<dx-popup ... (onShowing)="popup_showing($event)" (onShown)="popup_shown($event)" (onHiding)="popup_hiding($event)" (onHidden)="popup_hidden($event)"> </dx-popup>
import { DxPopupModule } from "devextreme-angular"; // ... export class AppComponent { popup_showing (e) { // Handler of the "showing" event } popup_shown (e) { // Handler of the "shown" event } popup_hiding (e) { // Handler of the "hiding" event } popup_hidden (e) { // Handler of the "hidden" event } } @NgModule({ imports: [ // ... DxPopupModule ], // ... })
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. This approach is more typical of jQuery.
var hiddenEventHandler1 = function (e) { // First handler of the "hidden" event }; var hiddenEventHandler2 = function (e) { // Second handler of the "hidden" event }; $("#popupContainer").dxPopup("instance") .on("hidden", hiddenEventHandler1) .on("hidden", hiddenEventHandler2);
See Also
- Handle Events: Angular | Vue | React | jQuery | AngularJS | Knockout | ASP.NET MVC 5 | ASP.NET Core
- Popup - Customize the Content
- Popup - Resize and Relocate
- Popup Demos
- Popup API Reference
If you have technical questions, please create a support ticket in the DevExpress Support Center.