How to display data in Bootstrap Modal when link button click in ASP.NET

18,278

Remove the data-toggle and update the code behind to be like this:

 protected void linkButton_Click(object sender, EventArgs e)
        {
            txtName.Text = "Name";
            txtEnail.Text = "[email protected]";
            Page.ClientScript.RegisterStartupScript(GetType(), "modelBox", "$("#myModal").modal('show');", true);
        }

It is better though to make the link button has a client side click event that gets the data through ajax, set the textboxs values and use the same modal('show') JavaScript function to display the modal box, this will be more efficient and user friendly.

Share:
18,278
Srinivas
Author by

Srinivas

Updated on June 05, 2022

Comments

  • Srinivas
    Srinivas almost 2 years

    How to display data in Bootstrap Modal when link button click in ASP.NET. In my code When i click on link button Modal is opening, but assign values are not displaying. Please tell me how to display modal with assigned values. Thanks.

    .aspx Code:

      <asp:LinkButton ID="linkButton8" runat="server" data-toggle="modal" data-target="#myModal" OnClick="linkButton_Click">CIS Information</asp:LinkButton>
    
          <div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel" align="center">Candidate Information Sheet</h4>
                            </div>
                            <div class="modal-body">
    
                                <table class="table table-bordered" align="center">
                                    <tr>
                                        <td>Name</td>
                                        <td>
                                 <asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
                                        <td>Email</td>
                                        <td>
                                            <asp:TextBox ID="txtEnail" runat="server"></asp:TextBox></td>
                                    </tr>
                                </table>
                            </div>
                            <div class="modal-footer">
                          <button type="button" class="btn btn-primary">Save</button>
                    <button type="button" class="btn btn-primary" data-ismiss="modal">Close</button>
                            </div>
                        </div>
                    </div>
                </div>
    

    C# Code:

     protected void linkButton_Click(object sender, EventArgs e)
            {
                txtName.Text = "Name";
                txtEnail.Text = "[email protected]";
            }
    
  • The Mahahaj
    The Mahahaj about 10 years
    Is your button within a form tag? If not try that.
  • DestiX
    DestiX almost 10 years
    LinkButton does not support UseSubmitBehavior: msdn.microsoft.com/en-us/library/…