我有以下编码结构:
<asp:Panel ID="Panel1" runat="server" Title="TestPanel" Visible="true">
<asp:GridView ID="grd1" runat="server" AutoGenerateColumns="true">
</asp:GridView>
<myControl:RepeaterUserControl ID="rpt"></myControl:RepeaterUserControl>
</asp:Panel>
The panel is used to control visibilty (currently set true for all time). The control RepeaterUserControl is a user control which contains a asp repeater with two buttons named Ok and Cancel (all initially set display:none). All this content of user control is shown on page as modal popup (using modal popup extender) on click of a Invoke button which is also a part of the user control.
<div id="div1" runat="server">
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="divDialog"
TargetControlID="btnDummyInvoker" CancelControlID="imbClose" PopupDragHandleControlID="divDialogTitle"
BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
<div style="height: 4px;">
</div>
<asp:Button ID="btnInvoke" runat="server" OnClick="btnInvoke_Click" Text="Invoke"
Width="90px" />
<div style="display: none; position: absolute;">
<asp:Button ID="Button2" runat="server" />
</div>
<div id="div2" runat="server" style="display: none;">
<asp:Repeater ID="rptList" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="lblName" runat="server" Text= <%# Eval("DisplayText").ToString() %> ></asp:Label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="btnOk" runat="server" OnClick="btnOk_Click" />
<asp:Button ID="btnCancel" runat="server" />
</div>
</div>
因此,用户在电网以下的网页上看到一个纽吨(Invoke),其中显示在电动波中重复控制以及Ok/Cancel纽吨。 复读者被分配到一个数据来源,其中列有项目清单,用户作改动,在烟 click点点点上,从背后的代码(在波茨克事件)一接重复器作为耳机。 项目。 有更多的行动要做。
Now the problem. If the user control is outside the panel it perfectly returns me the correct count of items, but if the userControl in inside the panel (as shown in code) the count returned on click of ok button is 0 after postback. why is the repeater losing its state in this case ?
<>Update>: 如果能够帮助解决问题,则从表面上添加法典。
//This is from the user control code
protected void btnInvoke_Click(object sender, EventArgs e)
{
rptList.DataSource = listToBeBoundToRepeater;
rptList.DataBind();
modalPopupExtender.Show();
}
//This is from the user control code
protected void btnOk_Click(object sender, EventArgs e)
{
for (int itemIndex = 0; itemIndex < rptList.Items.Count; itemIndex++)
{
// business logiv
}
}
rptList.Items.Count,在我所描述的案件出现倒退之后,为我开了。
update2 : Here is the weird solution I got, I enclosed the grid and repeater with a tag and set the runat property to server to make it a server control. Now its persisting the values of the repeater after postback properly. Strange, but working now.