how to get user control data when it's load dynamicly
i have a user control that have some properties.
public partial class ImageUpload : System.Web.UI.UserControl
{
public Image img = new Image();
protected void Page_Load(object sender, EventArgs e)
{
img.PG_Caption = txtImgCaption.Text;
img.PG_Visible = chkVisible.Checked;
img.File = fileImgUpload.FileBytes;
img.PG_FileName = fileImgUpload.FileName;
}
}
on another user control i load on page_load some of the first user control.
public partial class ImagesTab : System.Web.UI.UserControl
{
public int Count { get; set; }
public List<Image> Images
{
get { return GetImages(); }
}
private List<Image> GetImages()
{
List<Image> lI = new List<Image>();
foreach (Control ctl in plhImages.Controls)
{
}
return lI;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < Count; i++)
{
Control ImageUpload = LoadControl("ImageUpload.ascx");
plhImages.Controls.Add(ImageUpload);
Literal li = new Literal();
li.Text = "<br />";
开发者_如何学JAVA plhImages.Controls.Add(li);
}
}
}
}
how to implement the foreach loop on GetImages() to get the data ?
private List<Image> GetImages()
{
List<Image> lI = new List<Image>();
foreach (Control ctl in plhImages.Controls)
{
if (ctl is ImageUpload) lI.Add(((ImageUpload)ctl).img);
}
return lI;
}
精彩评论