Inserting a Web User Control at runtime
-
Hello, I'll get rigth to the point. In my asp .net website I created a few user controls (files with 'ascx' extension). My problem is that I tried in many ways to insert one of these controls on an aspx page at runtime depending on some triggers (let's say) and I didn't succede. Please help me with an idea or anything. Thanks in advance :)
-
Hello, I'll get rigth to the point. In my asp .net website I created a few user controls (files with 'ascx' extension). My problem is that I tried in many ways to insert one of these controls on an aspx page at runtime depending on some triggers (let's say) and I didn't succede. Please help me with an idea or anything. Thanks in advance :)
You can load a usercontrol dynamically using the Page's LoadControl method. So you just need some place to add the control. A PlaceHolder control is perfect for this. Drag the PlaceHolder on to the place where you want to load the user control. Then use the code
Control userControl = Page.LoadControl("myUserControl.ascx");
placeHolder1.Controls.Add(userControl);I don't think there's a limit to the nesting of usercontrols within usercontrols, but I could be wrong Kind regards - Jakob :cool: Three kinds of people in the world: - Those who can count.. - Those who can't!