views:

106

answers:

3

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?

+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
Make sure to add the control in the Page_Init event, not the Page_Load.
Ken Pespisa
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.
Have it in a config file. Then`foreach(Control c in ControlsReadFromConfig){Page.Controls.Add(c);}`
ram
where will it place that control?
Mike C.
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
I need the reference to the usercontrol in the markup so it can be moved, removed, modified.
Mike C.
A: 

The answer to my issue was to develop the form outside of Visual Studio.

Mike C.