views:

80

answers:

1

Hi All,

im basically creating a portal system, and want to load UserControls Dynamically, now i have read a couple of articles on this where they loading them into a placeholder, i have tried this. but it just seems a little buggy. its there not a better way to manage the viewstate etc

how does dotnetnuke do it where they inject the controls into regions/tablecells? and then how is the viewstate managed?

thanks in advanced...

+3  A: 

I don't have any DNN expereience, however if you do

protected override void OnInit(EventArgs e) {
    var control = UserControl.LoadControl("control.ascx");
    Page.Controls.Add(control);
}

This will load the control dynamically and add it to the page. You want to make sure you do it OnInit so that the control exists before viewstate is loaded. This way viewstate will be handed automatically.

Bob
thanks, by saying that, do usercontrols manage thier own viewstate? and this would then work by adding multiple usercontrols to the page correct?
Cwisking
It depenends on exactly what is in your `UserControl` If your `UserControl` contains standard ASP.NET Controls which manage their own ViewState then yes. If you have special values which need to be stored, the `UserControl` must impliment that themself.
Bob