Use UpdatePanel as below:
<div class="modal fade" tabindex="-1" role="dialog" id="mdlShowUserPass"> <div class="modal-dialog" role="document"> <asp:UpdatePanel runat="server"> <ContentTemplate> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Modal title</h4> </div> <div class="modal-body"> Your Content. Ex form </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <asp:Button ID="btnUpdate" runat="server" Text="Update" /> </div> </div> </ContentTemplate> </asp:UpdatePanel> </div> </div>
Surround the ' modal-content class using the UpdatePanel control. You can also open the modal code with a script manager, as shown below.
protected void ShowUserPass_Click(object sender, EventArgs e) { SQLHelper objSql = new SQLHelper(); objSql.SqlText = "select FirstName,LastName,Email from tblUserDetail"; DataTable dt = objSql.getDataTable(false); gvInvoices.DataSource = dt; gvInvoices.DataBind(); objSql.Close(); objSql.Dispose(); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "<script>$(function () {$('#mdlShowUserPass').modal({show:true,keyboard: false, backdrop: 'static'});});</script>", false);
If you want to close modal on the server side, add LinkButton and set the click event, use the scriptmanager again to hide the modality, changing show:false to true.
Edit
I missed your question. If you want the modal not to close when you click the button inside the modal, for example, to present a modal, etc., you can use the above solution.
However, if you want to open the modal after the postback, you can simply add the scriptmanager line to the clickbutton click event. No need to add update to modal.
Ravimallya
source share