Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Problem of ViewState with a custom data bound control


Message #1 by chn@n... on Wed, 13 Nov 2002 21:51:45
Hi all, 

I have a problem with the ViewState of a custom data bound control. I 
have created a custom data bound control (RepeaterFilmDisplay) that works 
fine when I introduce it directly in an aspx page but when I am defining 
another custom control containing it, the ViewState data of the data 
bound control are not recovered. 

Here is the code of the CreateChildControl of the custom controls 
embedding the custom data bound control. Do you understand why the 
ViewState of the repeaterFilmDisplay is not recovered whereas it is when 
introduced in an aspx page? 

Don?t hesitate to ask me more code if needed. 

Thanks in advance. 

Christian. 

protected override void CreateChildControls() 
{ 
  Controls.Clear(); 
  RepeaterFilmDisplay repeaterFilmDisplay = new RepeaterFilmDisplay(); 

  Controls.Add(repeaterFilmDisplay); 

  repeaterFilmDisplay.ID = "FilmsRepeater"; 
  repeaterFilmDisplay.EnableViewState = true; 
  repeaterFilmDisplay.TrackViewState(); 

  if (!this.Page.IsPostBack) 
  { 
    PersonsData personData = new 
    PersonsData(VideoWebTools.ConnectionString(this.Page)); 
    ArrayList al = personData.GetFilmsIdFromPersonId    
                    (VideoWebTools.VideoclubId(this.Page), PersonId); 

    ArrayList filmsForRepeater = new ArrayList(); 
    foreach (PersonsData.FilmSimpleDescription filmDescription in al) 
    { 
      filmsForRepeater.Add(new RepeaterFilmDisplay.FilmDescription 
                 (filmDescription.filmId, "", 
                  filmDescription.filmSupport1, 
                  filmDescription.filmSupport2)); 
    } 

    repeaterFilmDisplay.NbFilmToDisplay = 1; 
    repeaterFilmDisplay.FilmTransformFile = (VideoWebTools.TextRef 
               ("TransformFile.SimpleFilmDisplay", this.Page)); 
    repeaterFilmDisplay.DataSource = filmsForRepeater; 
    repeaterFilmDisplay.DataBind(); 
  } 
} 

  Return to Index