show the bootstrap modal from code behind

18,635

I figured out that if you move this two lines to the top ( inside the header ) it works,

 <script src="https://code.jquery.com/jquery.js"></script>
 <script src="Scripts/bootstrap.js"></script>

most of the people recommend put this two lines at the end, before the body ends, but I moved them to the header and it works.

Share:
18,635
omarmallat
Author by

omarmallat

Updated on June 04, 2022

Comments

  • omarmallat
    omarmallat almost 2 years

    I created an ASP.NET Web Application (webforms) using visual studio 2013. bootstrap has been created and working properly.

    my plan is to show a modal dialog which work perfectly as below using data-target attribute:

    <div id="confimDialog" class="modal fade" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title">Confirmation</h4>
                </div>
                <div class="modal-body">
                    <p>Your request has been submitted successfully.</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">Ok</button>
                </div>
            </div>
        </div>
    </div>
    <asp:Button runat="server" Text="Submit" data-target="#confirmDialog" />
    

    When I moved to the next step to show the confirmation from code behind, after executing some update in my database, the modal dialog never showed up:

    protected void Submit_Click(object sender, EventArgs e)
    {
        //my database codes here
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
    }
    

    and for sure I added the following script to my aspx page:

    <asp:Button runat="server" Text="Submit" CssClass="btn btn-primary" OnClick="Submit_Click" />
    <script>
        function Confirm () {
            $('#confirmDialog').modal('show'); 
            return true;
        };
    </script>
    

    I spent two days in this problem without any solution... I saw that there are some problem in showing a modal dialog from code behind, while many people say it's working using this codes. could you please help in this or propose any alternative solution to show a confirmation dialog from code behind???

    references: bootstrap modal problem in code behind

    thanks.