I
Invalidlastname
Hi,
We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue which is related to the repeater. In the code shown below, if I call Repeater1.Controls.Count in the OnInit (the code fragment was highlighted in yellow) , the viewstate for the repeater will be lost during the postback. You can re-produce this behavior by copying and pasting the code I provided, then you will know what is my issue.
BTW
The reason I call the Repeater.Controls.Count is because I have a generic function will recursively find the control I need and create a literal control for it. Currently I resolve this problem by excluding the repeater control, by checking the type of the control, in recursive routine.
ILN
--------------------------------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!Page.IsPostBack)
{
ArrayList ar = new ArrayList();
for (int i=0;i< 5;i++)
{
ar.Add(i);
}
Repeater1.DataSource = ar;
this.DataBind();
}
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
// <<<demo demo demo
bool bDemoLoadViewstateFailedInRepeater = false;
bDemoLoadViewstateFailedInRepeater = true;
if (bDemoLoadViewstateFailedInRepeater)
{
// the following line will cause repeater failed to load the viewstate
int i = Repeater1.Controls.Count ;
}
// demo demo demo>>>
}
We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue which is related to the repeater. In the code shown below, if I call Repeater1.Controls.Count in the OnInit (the code fragment was highlighted in yellow) , the viewstate for the repeater will be lost during the postback. You can re-produce this behavior by copying and pasting the code I provided, then you will know what is my issue.
BTW
The reason I call the Repeater.Controls.Count is because I have a generic function will recursively find the control I need and create a literal control for it. Currently I resolve this problem by excluding the repeater control, by checking the type of the control, in recursive routine.
ILN
--------------------------------------------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!Page.IsPostBack)
{
ArrayList ar = new ArrayList();
for (int i=0;i< 5;i++)
{
ar.Add(i);
}
Repeater1.DataSource = ar;
this.DataBind();
}
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
// <<<demo demo demo
bool bDemoLoadViewstateFailedInRepeater = false;
bDemoLoadViewstateFailedInRepeater = true;
if (bDemoLoadViewstateFailedInRepeater)
{
// the following line will cause repeater failed to load the viewstate
int i = Repeater1.Controls.Count ;
}
// demo demo demo>>>
}