开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜