AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Thursday, 14 July 2016

How to create custom modal popup in bootstrap?

In this article I will discuss How to create custom modal popup in bootstrap? Please check below code to create modal popup.

Add HTML Modal div
<!-- Modal -->
<div class="modal fade" id="confirm-modal" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Confirmation</h4>
            </div>
            <div class="modal-body">
                <p id="modal-msg">Confirm message will append here.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="btnok">Ok</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            </div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="alert-modal" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Alert!</h4>
            </div>
            <div class="modal-body">
                <p id="modal-msg-alert">Alert message will append here.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Ok</button>
            </div>
        </div>
    </div>
</div>

Add JavaScript functions
function ModalConfirm(msg, postbackurl) {
    $('#modal-msg').html(msg);
    $('#confirm-modal').modal({ backdrop: 'static', keyboard: false })
    .one('click', '#btnok', function () {
        if (postbackurl != '') {
            window.location = postbackurl;
        }
    });
}

function ModalAlert(msg) {
    $('#modal-msg-alert').html(msg);
    $('#alert-modal').modal({ backdrop: 'static', keyboard: false })
}

Call these JavaScript functions to show alert

Alert Popup

Confirm Popup

0 comments :

Post a Comment

  • Popular Posts
  • Comments