Enable Button on another Button Click and open Bootstrap Modal Popup using jQuery in ASP.Net

Last Reply 6 months ago By pandeyism

Posted 6 months ago

on selecting  modal 1 i want the button modal 3 to display and on selecting modal 2 the button modal 3 should display.

on selecting modal i want my button to be enable and after that on clicking the button that particular modal should be displayed 

<script>
    $(document).ready(function () {
        $("#myBtn").click(function () {
            $("#myModal").modal({ show: true });
        });
        $("#Button1").click(function () {
            $("#Div1").modal({ show: true });
        });
        $("#Button2").click(function () {
            $("#Div2").modal({ show: true });
        });

    });
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <form id="Form2" runat="server">
    <div class="container">
        <h2>
            Activate Modal with JavaScript</h2>
        <!-- Trigger the modal with a button -->
        <button type="button" class="btn btn-info btn-lg" id="myBtn" style="margin-bottom: -66px;
            margin-left: -185PX;">
            Modal 3</button>
        <!-- Modal -->
        <div class="modal fade" id="myModal" 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">
                            Modal Header</h4>
                    </div>
                    <div class="modal-body">
                        <p>
                            Some text in the modal.</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            Close</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <button type="button" class="btn btn-info btn-lg" id="Button1">
        Modal 2</button>
    <!-- Modal -->
    <div class="modal fade" id="Div1" 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">
                        Modal Header</h4>
                </div>
                <div class="modal-body">
                    <p>
                        Some text in the modal.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        Close</button>
                </div>
            </div>
        </div>
    </div>
    <button type="button" class="btn btn-info btn-lg" id="Button2">
        Modal 1</button><br />
    <!-- Modal -->
    <div class="modal fade" id="Div2" 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">
                        Modal Header</h4>
                </div>
                <div class="modal-body">
                    <p>
                        Some text in the modal.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        Close</button>
                </div>
            </div>
        </div>
    </div>
    <br />
    <asp:Button ID="Button3" runat="server" Text="Button" />
    </form>
</body>

 

You are viewing reply posted by: pandeyism 6 months ago.
Posted 6 months ago

Hey v@run,

Please refer below sample.

HTML

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script type="text/javascript">
    $(document).ready(function () {
        $("#myBtn").click(function () {
            $("#myModal").modal({ show: true });
        });
        $("#Button1").click(function () {
            $("#myBtn").show();
        });
        $("#Button2").click(function () {
            $("#myBtn").show();
        });
    });
</script>
<div class="container">
    <!-- Trigger the modal with a button -->
    <button type="button" class="btn btn-info btn-lg" id="myBtn" style="display: none">
        Modal 3</button>
    <!-- Modal -->
    <div class="modal fade" id="myModal" 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">
                        Modal Header</h4>
                </div>
                <div class="modal-body">
                    <p>
                        Some text in the modal 3.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        Close</button>
                </div>
            </div>
        </div>
    </div>
    <button type="button" class="btn btn-info btn-lg" id="Button1">
        Modal 1</button>
    <!-- Modal -->
    <div class="modal fade" id="Div1" 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">
                        Modal Header</h4>
                </div>
                <div class="modal-body">
                    <p>
                        Some text in the modal 1.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        Close</button>
                </div>
            </div>
        </div>
    </div>
    <button type="button" class="btn btn-info btn-lg" id="Button2">
        Modal 2</button><br />
    <!-- Modal -->
    <div class="modal fade" id="Div2" 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">
                        Modal Header</h4>
                </div>
                <div class="modal-body">
                    <p>
                        Some text in the modal 2.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        Close</button>
                </div>
            </div>
        </div>
    </div>
</div>

Screenshot