By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,663 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,663 IT Pros & Developers. It's quick & easy.

Loading UserControls dynamically

P: n/a
I'm working on a WebForm, that through some tabs can load and contain
a number of different "plugin" UserControls, all derived from the same
"plugin" super class - a bit like the IBuySpy portal.

An XML file defines which plugins are available and should be listed
in my tab control. When the user clicks on as tab, the page should
load the corresponding UserControl into a panel via Page.LoadControl
and Controls.Add.

This works fine, but when the "plugin" controls raises a postback, for
example when a DataGrid in the control raises the SortCommand event,
the control is lost and of course the event handler for SortCommand
will not be executed.

I have tried to save information in the page viewstate about which
control is currently loaded and then in the Page_Load event handler
load the control again, but somehow the control doesn't obtain it's
viewstate from before the postback. For example one of the controls
contains a DataGrid, that looses all it's data, unless I set the
DataSource and calls DataBind again, which should not be necessary.

I guess this all comes down to two things:
1. What do I have to do to ensure that UserControls load via
Page.LoadControl and Controls.Add are present has obtained it's
viewstate after a postback?
2. When in the page process cycle should the above be done?

Best regards
Hendrik W. Hansen
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.