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 ::..The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.