我在Bootstrap 3可折叠面板中有一个表单。
表单是带有EDIT和DELETE按钮的asp.net DetailsView
控件。
当我点击编辑时,面板会折叠,我需要再次点击它以重新打开它并完成编辑。
EDIT按钮单击事件会导致面板关闭。
为什么呢?我该如何预防?
这是标记(注意:手风琴在UpdatePanel
内):
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">Associated Person Details
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<asp:DynamicValidator runat="server" ID="DynamicValidator5" ControlToValidate="dvPartnerDetails" Display="None" EnableClientScript="true" />
<h4>Partner details:</h4>
<asp:DetailsView ID="dvPartnerDetails" runat="server" CssClass="detailstable" FieldHeaderStyle-CssClass="bold" AutoGenerateRows="false" DefaultMode="ReadOnly" EnableModelValidation="true" OnDataBound="dvPartnerDetails_DataBound" DataSourceID="dsPartnerDetails" DataKeyNames="PersonID">
<Fields>
<asp:DynamicField DataField="PartnerTitle" />
<asp:DynamicField DataField="PartnerForenames" />
<asp:DynamicField DataField="PartnerInitials" />
<asp:DynamicField DataField="PartnerSurname" />
<asp:DynamicField DataField="PartnerAddressee" />
<asp:DynamicField DataField="PartnerSalutation" />
</Fields>
<FieldHeaderStyle CssClass="bold" />
<FooterTemplate>
<div class="bottomhyperlink">
<asp:LinkButton ID="EditHyperLink" CausesValidation="false" CssClass="btn btn-default" runat="server" CommandName="Edit">Edit</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CssClass="btn btn-default" CausesValidation="false" CommandName="Delete" OnClientClick='return confirm("Are you sure you want to delete this record?");' Text="Delete" />
</div>
</FooterTemplate>
</asp:DetailsView>
</div>
</div>
</div>
答案 0 :(得分:1)
问题是updatepanel总是带来原始代码,你需要重新打开手风琴。
<script type='text/javascript'>
$(document).ready(function() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
});
function endRequestHandler(sender, args)
{
$('#collapseTwo').collapse.in()
}
</script>
答案 1 :(得分:1)
这可能对其他人有帮助。
达到预期效果的正确方法如下:
<script type='text/javascript'>
$(document).ready(function() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
});
function endRequestHandler(sender, args)
{
$('#collapseTwo').addClass('in');
}
</script>
答案 2 :(得分:0)
这个解决方案有效,但我需要一个更灵活的解决方案,并没有假设哪个手风琴是开放的。请参阅我在其他问题中发布的解决方案: