【问题标题】:Bootstrap modal close button does not cause postbackBootstrap 模态关闭按钮不会导致回发
【发布时间】:2013-09-13 01:55:19
【问题描述】:
我有一个 boostrap 模态,这里是关闭它的按钮:
<div class="modal-footer">
<asp:Button ID="btnClose" CssClass="btn" runat="server" Text="Close" data-dismiss="modal" aria-hidden="true" />
</div>
按钮和模式表单嵌套在更新面板中。但它不会触发回发,因此更新面板不会做它的事情。如果我删除数据关闭,那么它不会关闭模式。
我能做什么?
【问题讨论】:
标签:
c#
javascript
asp.net
【解决方案1】:
您可以像在您的示例中一样使用 ASP 按钮
<div class="modal-footer">
<asp:Button ID="btnClose" CssClass="btn" runat="server" Text="Close" data-dismiss="modal" aria-hidden="true" />
</div>
试试 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>
这将关闭模式并触发回发
【解决方案2】:
Data-dismiss 是基于 javascript 的,只是隐藏了模式。如果您希望关闭按钮回发,您需要使用 OnClick 属性并在您的代码隐藏中添加一个方法来处理它:
<asp:Button ID="btnClose" CssClass="btn" runat="server" Text="Close" data-dismiss="modal" aria-hidden="true" OnClick="YourMethodNameGoesHere"/>
然后在你的代码隐藏中......做一些事情:
protected void YourMethodNameGoesHere()
{
// Do stuff
}