长期读者第一次海报
我有一个链接到母版页的内容页。master 有 toolkitscriptmanager。在内容页面上,我在父转发器的项目模板中有一个嵌套转发器,我有一个用于子转发器控件的 CollapsiblePanelExtender。在部分回发时,如果未设置折叠属性,则所有面板都会展开。如果collapsed 属性设置为true,那么所有面板在部分回发时都会折叠。
中继器的数据绑定发生在后面代码的 page_init 部分,我通过遍历 page_load 事件中的项目来检查面板的状态。似乎没有任何工作,在调试代码时,我确实看到了正确设置的属性,但是在浏览器中呈现时,所有面板都是打开的。触发部分回发的编辑事件在 modalpopup 中执行。
我试图将面板移动到他们自己的更新面板中,删除更新面板,将模式放在更新面板之外无济于事。不维护 ViewState。
页面代码:
<asp:Repeater ID="rptrConsultants" runat="server" OnItemCommand="rptrConsultants_ItemCommand" OnItemDataBound="rptrConsultants_ItemDataBound">
<HeaderTemplate>
<div class="pageTitle">
Your Consultants (Click on the image beside the consultant to view their group memberships)
<br />
Official names are listed. Expanding the consultant will show the name assigned and the related groups.
</div>
<br />
<table>
<tr>
<td style="width: 60px; font-weight: bold; text-align: center;">
Actions
</td>
<td style="font-weight: bold;">
Consultant information
</td>
</tr>
</HeaderTemplate>
<FooterTemplate>
</table>
<asp:Label ID="lblNoConsultant" runat="server" Text="You have not created any consultants" Visible="false"></asp:Label>
</FooterTemplate>
<ItemTemplate>
<tr>
<td style="width: 60px; text-align: center;">
<asp:Image ID="imgConsultantExpander" runat="server" ToolTip="Click here to toggle consultant details" AlternateText="Toggle Consultant Details" />
<asp:ImageButton ID="btnDeleteConsultant" AlternateText="Delete Consultant" runat="server" CausesValidation="false" CommandName="DeleteConsultant" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "IndividualsID")%>' ImageUrl="~/Styles/Images/Icons/remove_consultant.png" ToolTip="Delete consultant" />
<asp:ImageButton ID="btnAddConsultantToNewGroup" AlternateText="Add consultant to a new group" runat="server" CommandName="AddConsultantToGroup" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "IndividualsID")%>' ImageUrl="~/Styles/Images/Icons/add_user_to_group.png" ToolTip="Add consultant to a new group" />
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Name")%>
(<%#DataBinder.Eval(Container.DataItem, "UserID") %>)
<asp:Label ID="lblGroupCount" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Panel ID="pnlConsultantExpander" runat="server">
<asp:Repeater ID="rptrConsultantGroups" runat="server" DataSource='<%#Container.DataItem.Row.GetChildRows("ConsultantGroupRelation") %>' OnItemCommand="rptrConsultantGroups_ItemCommand">
<HeaderTemplate>
<table style="margin-left: 50px;">
<tr>
<td style="width: 40px; text-align: center; font-weight: bold;">
Actions
</td>
<td style="font-weight: bold;">
Membership
</td>
<td style="font-weight: bold;">
Nick Name
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="width: 40px;">
<asp:ImageButton ID="btnEditConsultant" AlternateText="Edit Consultant" runat="server" CommandName="EditConsultantInGroup" CommandArgument='<%#Container.DataItem("GroupID") & "|" & Container.DataItem("GroupMembershipID")%>' ImageUrl="~/Styles/Images/Icons/edit_consultant.png" />
<asp:ImageButton ID="btnDeleteConsultant" AlternateText="Remove from group" runat="server" CommandName="DeleteConsultantFromGroup" CommandArgument='<%#Container.DataItem("GroupID") & "|" & Container.DataItem("GroupMembershipID")%>' ImageUrl="~/Styles/Images/Icons/delete_fromgroup.png" ToolTip="Remove from group" />
</td>
<td class="textbold">
<%#Container.DataItem("GroupName")%>
</td>
<td class="textitalic">
<%#Container.DataItem("nickname")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
<asp:CollapsiblePanelExtender ID="cpepnlConsultantExpander" runat="server" TargetControlID="pnlConsultantExpander" CollapseControlID="imgConsultantExpander" ExpandControlID="imgConsultantExpander" CollapsedImage="~/Styles/Images/Icons/user_info.png" ExpandedImage="~/Styles/Images/Icons/user_open.png" ImageControlID="imgConsultantExpander" EnableViewState="true" CollapsedSize="0" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
然后是 page_load 中发生的方法背后的代码:
Private Sub setCollapsiblePanelsInRepeater(ByVal rptr As Repeater)
For Each item As RepeaterItem In rptr.Items
If ((item.ItemType = ListItemType.AlternatingItem) Or (item.ItemType = ListItemType.Item)) Then
For Each ctl As Control In item.Controls
If (TypeOf ctl Is AjaxControlToolkit.CollapsiblePanelExtender) Then
Dim cpe As AjaxControlToolkit.CollapsiblePanelExtender = DirectCast(ctl, AjaxControlToolkit.CollapsiblePanelExtender)
If (Not IsPostBack()) Then
cpe.Collapsed = True
cpe.ClientState = "true"
Else
Dim isCollapsed As Boolean
If (Request.Form(cpe.UniqueID & "_ClientState") IsNot Nothing) Then
isCollapsed = (Request.Form(cpe.UniqueID & "_ClientState").ToString() = "true")
Else
isCollapsed = True
End If
If (isCollapsed) Then
cpe.ClientState = "true"
cpe.Collapsed = True
Else
cpe.ClientState = "false"
cpe.Collapsed = False
End If
End If
End If
Next
End If
Next
End Sub
请注意,初始加载事件有效!面板在页面加载时全部折叠
另请注意,转发器嵌套在 tabPanel
预先感谢您的回答!
抱歉冗长的解释
编辑:
更新:
尝试了 Javascript 路由 - 仍然无济于事
pageLoad = function()
{
CheckStatusOfPanels();
};
function CheckStatusOfPanels()
{
var allBehaviors = Sys.Application.getComponents();
for (var loopIndex = 0; loopIndex < allBehaviors.length; loopIndex++)
{
currentBehavior = allBehaviors[loopIndex];
if (currentBehavior._name && currentBehavior.get_name() == 'CollapsiblePanelBehavior')
{
var myID = currentBehavior.get_id() + '_ClientState';
var isCollapsed = document.getElementById(myID).value
if (isCollapsed == 'true')
{
currentBehavior.expandPanel();
currentBehavior._ClientState = isCollapsed;
}
else
{
currentBehavior.collapsePanel();
currentBehavior._ClientState = isCollapsed;
}
}
}
}
** 更新 #2 **
我的代表不到 100,所以我必须等待 8 小时才能回答我自己的问题:
这是我几乎整天工作后的“修复”:
好的,终于找到了解决方案。它是这样的:
使用在我的原始帖子中发布的 SetCollapsiblePanelsInRepeater 方法,我在 updatePanel prerender 方法中添加了对该方法的调用,瞧,面板现在保留了它们的状态......
Protected Sub updtpnlMain_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles updtpnlMain.PreRender
setCollapsiblePanelsInRepeater(rptrGroups)
setCollapsiblePanelsInRepeater(rptrConsultants)
End Sub
对于 Clarity for others 谷歌搜索这个问题,设置面板事件的方法是:
Private Sub setCollapsiblePanelsInRepeater(ByVal rptr As Repeater)
For Each item As RepeaterItem In rptr.Items
If ((item.ItemType = ListItemType.AlternatingItem) Or (item.ItemType = ListItemType.Item)) Then
For Each ctl As Control In item.Controls
If (TypeOf ctl Is AjaxControlToolkit.CollapsiblePanelExtender) Then
Dim cpe As AjaxControlToolkit.CollapsiblePanelExtender = DirectCast(ctl, AjaxControlToolkit.CollapsiblePanelExtender)
If (Not IsPostBack()) Then
cpe.Collapsed = True
cpe.ClientState = "true"
Else
Dim isCollapsed As Boolean
If (Request.Form(cpe.UniqueID & "_ClientState") IsNot Nothing) Then
isCollapsed = (Request.Form(cpe.UniqueID & "_ClientState").ToString() = "true")
Else
isCollapsed = True
End If
If (isCollapsed) Then
cpe.ClientState = "true"
cpe.Collapsed = True
Else
cpe.ClientState = "false"
cpe.Collapsed = False
End If
End If
End If
Next
End If
Next
End Sub