the answer is here: Find a image in code behind
I use this :
((Image)FindControlRecursive<Image>(this,
String.Format("Image{0}", Convert.ToString(i)))).ImageUrl =
String.Format("~/images/prettyPhoto/{0}/fullscreen/{1}.jpg",
SelectedAlbum.ToString(), Convert.ToString(i));
and also use this method that Antonio Bakula gives:
public static T FindControlRecursive<T>(Control holder, string controlID) where T : Control
{
Control foundControl = null;
foreach (Control ctrl in holder.Controls)
{
if (ctrl.GetType().Equals(typeof(T)) &&
(string.IsNullOrEmpty(controlID) || (!string.IsNullOrEmpty(controlID) && ctrl.ID.Equals(controlID))))
{
foundControl = ctrl;
}
else if (ctrl.Controls.Count > 0)
{
foundControl = FindControlRecursive<T>(ctrl, controlID);
}
if (foundControl != null)
break;
}
return (T)foundControl;
}
The problem was that the FindControl
didn't work for images.