简体   繁体   中英

Bootstrap modal not working with button click

I'm trying to make a modal called acceptModal to appear when button acceptButton is clicked using JavaScript. However, the modal does not seem to be appearing but the background does turn dark. Any ideas?

Button

<asp:button runat="server" type="button" CssClass="btn btn-success mr-xs mb-sm buttonwidth" Text="Accept" ID="acceptButton" OnClick="acceptButton_Click1"></asp:button>

C#

protected void acceptButton_Click1(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
}

Modal

<div class="modal right fade" id="acceptModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
    <div class="modal-dialog" role="document">
        <div class="modal-content">

        <div class="modal-header" style="background-color:#01d36b;box-shadow:0 2px 10px 0 rgba(0,0,0,.16)">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <p style="margin:0;padding:10px;color:#fff;font-size:18px;">Order Checkout</p>

            </div>

            <div class="modal-body" style="padding:10px;">
                <p>Hi<p>
            </div>

        </div>
    </div>
</div>

JS

<script type="text/javascript">
function openModal() {
    $('#acceptModal').modal('show');
}
</script>

Try below code if you want to show model from code-behind button click acceptButton_Click1 :

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script type='text/javascript'>");
sb.Append("$('#acceptModal').modal('show');");
sb.Append(@"</script>");
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "DetailModalScript", 
                                        sb.ToString(), false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM