jmasterx
jmasterx

Reputation: 54183

Bootstrap modal close button does not cause postback

I have a boostrap modal, and here is the button to close it:

 <div class="modal-footer">
 <asp:Button ID="btnClose" CssClass="btn" runat="server" Text="Close" data-dismiss="modal" aria-hidden="true" />
 </div>

The Button and modal form are nested in an update panel. But it does not trigger a postback so the update panel does not do its thing. If I remove data dismiss then it will not close the modal.

What could I do?

Upvotes: 2

Views: 5902

Answers (2)

bjvilory
bjvilory

Reputation: 586

You can use the ASP Button like in your example

<div class="modal-footer">
     <asp:Button ID="btnClose" CssClass="btn" runat="server" Text="Close" data-dismiss="modal" aria-hidden="true" />
</div>

just try the UseSubmitBehavior="false"

<div class="modal-footer">
   <asp:Button ID="btnClose" CssClass="btn" runat="server" Text="Close" data-dismiss="modal" aria-hidden="true" UseSubmitBehavior="false" />
</div>

this will close the modal and trigger a postback

Upvotes: 8

Troy Carlson
Troy Carlson

Reputation: 3121

Data-dismiss is javascript based and just hides the modal. If you want the close button to postback, you'll need to use the OnClick property and add a method to handle that in your code-behind:

<asp:Button ID="btnClose" CssClass="btn" runat="server" Text="Close" data-dismiss="modal" aria-hidden="true" OnClick="YourMethodNameGoesHere"/>

Then in your code-behind...do something:

protected void YourMethodNameGoesHere()
{
    // Do stuff
}

Upvotes: 2

Related Questions