Skip to content

Instantly share code, notes, and snippets.

@MaheshHika
Created November 10, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaheshHika/b1c4005aa5fabb9ae487440d4adf3ac4 to your computer and use it in GitHub Desktop.
Save MaheshHika/b1c4005aa5fabb9ae487440d4adf3ac4 to your computer and use it in GitHub Desktop.
[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