Steps to reproduce:
1. Create a new Test web part with this simple repeater
Test.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Test.ascx.cs" Inherits="CMSWebParts_Test" %>
<asp:Panel ID="PanelMain" runat="server">
<table cellpadding="0" cellspacing="0" width="40%" align="center" border="2">
<tr>
<td>
<asp:Repeater ID="rptEmployee" runat="server">
<HeaderTemplate>
<table>
<tr>
<th width="100px" align="center">
EmployeeID
</th>
<th width="100px" align="center">
DepartmentID
</th>
<th width="100px" align="center">
Name
</th>
<th width="100px" align="center">
Country
</th>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td width="100px" align="center">
<%# ((Employee)Container.DataItem).EmpID %>
</td>
<td width="100px" align="center">
<%# ((Employee)Container.DataItem).DeptID %>
</td>
<td width="100px" align="center">
<%# ((Employee)Container.DataItem).EmpName %>
</td>
<td width="100px" align="center">
<%# ((Employee)Container.DataItem).Country %>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
</table><br />
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Panel>
Test.ascx.cs:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.PortalControls;
using CMS.CMSHelper;
using System.Data;
public partial class CMSWebParts_Test : CMSAbstractWebPart
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
rptEmployee.DataSource = EmployeeList.emplst;
rptEmployee.DataBind();
}
}
public class EmployeeList
{
static EmployeeList()
{
emplst = new List<Employee>();
emplst.Add(new Employee() { EmpID = 1, DeptID = 1, EmpName = "Smith", Country = "USA" });
emplst.Add(new Employee() { EmpID = 2, DeptID = 4, EmpName = "Adam", Country = "Japan" });
emplst.Add(new Employee() { EmpID = 3, DeptID = 3, EmpName = "Sara", Country = "China" });
emplst.Add(new Employee() { EmpID = 4, DeptID = 4, EmpName = "Ram", Country = "India" });
emplst.Add(new Employee() { EmpID = 5, DeptID = 3, EmpName = "Kalvin", Country = "UK" });
}
public static List<Employee> emplst { get; set; }
}
public class Employee
{
public int EmpID { get; set; }
public int DeptID { get; set; }
public string EmpName { get; set; }
public string Country { get; set; }
}
}
2. Create a Blank Web Site (no content in it)
3. Register Test web part with the site
4. Place the part on a single page of the blank site
5. Run site. Web part displays a table of Employees
6. Click Button
7. Data disappears after postback
8. Create a new web project in VS2010
9. Create a new page
10. Create a new custom control with exact the same code as above
11. Place the control on the empty page
12. Run site and click the button
13. The repeater retains the data
Vlado