The database returns the filename of the user control (i.e. UserControl.ascx), and a value (tdr.Page) to determine which placeholder it should load into.
I then use Server.MapPath to get the path to the user control but when it comes down to Load the control I keep getting the error "filepath\usercontrol.ascx is not a valid virtual path". Can anyone please help me solve this problem?
here is the code i am using:
Expand|Select|Wrap|Line Numbers
- string component = tdr.UserControl;
- string componentPath = Server.MapPath(component);
- switch (tdr.Page)
- {
- case "Page1":
- {
- PlaceHolder ph = (PlaceHolder)PageView1.FindControl("Page1PlaceHolder");
- ph.Controls.Add(Page.LoadControl(componentPath)); //where I get the error
- break;
- }
- case "Page2":
- {
- PlaceHolder ph = (PlaceHolder)PageView2.FindControl("Page2PlaceHolder");
- ph.Controls.Add(Page.LoadControl(componentPath)); //error
- break;
- }
- }