i have a user control that has a few inner controls like lables and images that represents a "movie".
from a web page i get a list of movies (List<Movie>) and for each movie in the list i want to generate my user control and add it to a panel.
(i added a movie type data member to the user control)
List<Movie> movies = movieRepo.GetAllMovies();
foreach (Movie movie in movies)
MovieControl movieControl = new MovieControl();
movieControl.Movie = movie;
in my Movie user control i created a method that populates the movie information:
public void PopulateMovieInfo()
img_Movie.ImageUrl = movie.ImgURL;
img_Movie.PostBackUrl = string.Format("AnotherPage.aspx");
lbl_Description.Text = movie.Description;
lbl_Director.Text = movie.Director;
lbl_Genre.Text = movie.Genre.ToString();
lbl_LengthInMin.Text = movie.LengthInMin.ToString();
lbl_Title.Text = movie.Title;
when this method is called within the foreach loop, all the sub controls of the movie user control are null. why is this?
i should say that i generate all the movie controls (code 1) in the Page_Load method.Read more...