How do i Dynamically load UserControls the correct way?
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 a开发者_Python百科dvance...
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.
精彩评论