Does anybody know if it's possible to add a user control to a web form in Visual Studio 2008, but to not have its declaration added to the designer file?
views:
106answers:
3
+1
A:
As long as you know the path of the control (either programatically or from DB/config) you can do
Page.Controls.Add("pathToYourControl");
ram
2010-01-07 21:21:14
Make sure to add the control in the Page_Init event, not the Page_Load.
Ken Pespisa
2010-01-07 21:22:53
That sounds good, but I would like a way I can add/remove/modify the user control from the .aspx file on the web server, and not have to recompile and redeploy.
Mike C.
2010-01-07 21:36:14
Have it in a config file. Then`foreach(Control c in ControlsReadFromConfig){Page.Controls.Add(c);}`
ram
2010-01-07 21:39:35
where will it place that control?
Mike C.
2010-01-07 21:46:01
A:
Use can use Page.LoadControl, examples in both links:
void Page_Init(object sender, System.EventArgs e)
{
// Instantiate the UserControl object
MyControl myControl1 =
(MyControl)LoadControl("TempControl_Samples1.ascx.cs");
PlaceHolder1.Controls.Add(myControl1);
}
A Good Example of Asp.net LoadControl with multiple parameters
rick schott
2010-01-07 21:45:25
I need the reference to the usercontrol in the markup so it can be moved, removed, modified.
Mike C.
2010-01-08 04:13:27
A:
The answer to my issue was to develop the form outside of Visual Studio.
Mike C.
2010-06-14 18:36:23