Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[ToolboxItemAttribute(false)]
public class CustomWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/15/test/CustomControl.ascx";
private const string RelativeFolderCss = "../ReferencedFiles/css";
private const string RelativeFolderJs = "..ReferencedFiles/js";
protected override void CreateChildControls()
{
IModuleBinder moduleBinder = new ModuleBinder();
List<List<HtmlGenericControl>> consolidatedControls = new List<List<HtmlGenericControl>>();
List<HtmlGenericControl> metaTags = new List<HtmlGenericControl>();
metaTags = moduleBinder.ControlDefinitionMetaTags();
consolidatedControls.Add(metaTags);
List<HtmlGenericControl> javascriptControls = new List<HtmlGenericControl>();
javascriptControls = moduleBinder.ControlDefinitionJavascripts(RelativeFolderJs);
consolidatedControls.Add(javascriptControls);
List<HtmlGenericControl> cssControls = new List<HtmlGenericControl>();
cssControls = moduleBinder.ControlDefinitionCss(RelativeFolderCss);
consolidatedControls.Add(cssControls);
foreach (List<HtmlGenericControl> genericControls in consolidatedControls)
{
foreach (HtmlGenericControl htmlControls in genericControls)
{
this.Controls.Add(htmlControls);
}
}
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.