If you are developing a custom fieldtype and therefore building the rendering template, the .ascx file, you normally deploy it to the template/controltemplates/ folder. But what if you want to deploy your files into custom subfolders which you can name like the project they belong to. This is the code which calls the Controls from your template normally:
myLabel = (Label)TemplateContainer.FindControl(“myLabel”);
But if you deploy them into a subfolder, the normal code does not find these controls in subfolders. So i found this nice article. Erik Burger wrotes how to achieve it. You have to use this code:
// Initialize template container templateContainer = new TemplateContainer(); Control myControl = (Control)Page.LoadControl("~/_controltemplates/MyProjects/myControlRenderingTemplate.ascx" ); templateContainer.Template = ((RenderingTemplate)myControl.Controls).Template; // Add the container Controls.Add(templateContainer); //Now you find the your label by using this: myLabel = (Label)templateContainer.FindControl("myLabel");
Normally SharePoint should also look into the subdirectories, but for some reasons it does not work, so maybe this helps you, too.
My posts about custom fieldtypes:
- SharePoint 2010 I like custom fieldtypes
- SharePoint 2010 Access other fields of a form of custom fieldtype
- SharePoint 2010 A custom fieldtype for Hyperlinks
..:: I LIKE SHAREPOINT ::..