Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Maintaining State
Message
De
05/03/2003 16:21:33
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Maintaining State
Divers
Thread ID:
00761789
Message ID:
00761789
Vues:
60
This problem is driving me crazy, I hope someone has some practical ideas.

I have a UserControl that I am adding programmatically to my WebForm when a User clicks a choice.
this.oMyControl = (MyControl)LoadControl("MyControl.ascx");
this.oMyControl.oData = this.oData;
this.MyPanel.Controls.Add(this.oMyControl);

this.DataBind();
OK, this works fine. I have persisted my DataSet in the ViewState (because it's a small DataSet, I don't have a problem with doing this). In the UserControl I have several TextBox controls, that are filled from the DataSet. And this works fine as well.

The problem I'm having is trying to save changes the user makes in the TextBoxes on the UserControl. This is because I don't just have *one* UserControl ... this form can have several UserControls (only one instantiates on the page at a time) and I'd like to be able to preserve any changes in any of the TextBox controls, even when the user clicks on another choice and a different UserControl instantiates.

What happens currently is that when another choice is made, and the page posts back to the server, the this.MyPanel.Controls.Count is 0 ... IOW, this.oMyControl is no longer contained in this.MyPanel.Controls. Why not? I'm guessing it would have something to do with ViewState, but I'm not exactly sure how to add this.oMyControl to the ViewState, or even if I'm approaching this from the right angle. oMyControl has EnableViewState true and so does MyPanel. I seem to remember reading somewhere about problems with keeping programmatically added UserControls in the ViewState, but I can't find any practical ways of making sure it gets added.

I'm sure I'm not explaining this very well, but hopefully one of you guys will get the gist of what I'm saying and what I'm asking about.

Any suggestions from someone who's been there?

TIA,
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform