Hallo,
Recently I have read a couple of posts on varous sites and blogs that ASP.NET Repeater one of the most commonly used and accepted between experienced programmers. Someone actually wrote that he consider the asp.net programmer better if he mentions that he often use this control in a job interview. The fact that I used it rarely maybe makes me a beginner :) This is implementation I have used when I needed some control repeated dynamically.
public class MyUserControl:UserControl
{
LocalizedCheckBox chb;
LocalizedLabel lbl;
TextBox txt;
public MyUserControl()
{
//Instantiate controls
//do something with them
}
public bool Checked
{
get{ return chb.Checked;}
}
public string Text
{
get{ return txt.Text; }
}
}
public partial class MyParentControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
foreach('something')
{
MyUserControl ctr = new MyUserControl();
ctr.Text="some value";
ctr.Checked= false;
this.Panel1.Controls.Add(ctr);
}
}
protected void btn_Click(object sender, EventArgs e)
{
foreach (MyUserControl dControl in this.Panel1.Controls.OfType<MyUserControl>())
{
//do something
string text = dControl.Text;
}
}
}
I have never had a problem with this code even when I added the events on MyUserControl. Of course, that it's possible to achieve the same with repeater control, but I would like to know why(or is it) better to use repeater.
What are the benefits if I use repeater instead?
Thanks