Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 757
jmasterx Avatar asked Sep 25 '26 11:09

jmasterx


2 Answers

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

like image 133
bjvilory Avatar answered Sep 28 '26 02:09

bjvilory


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
}
like image 26
Troy Carlson Avatar answered Sep 28 '26 00:09

Troy Carlson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!