1. Create a visual webpart
2. Add the below code to load the user control
namespace SimpleWebPart.VisualWebPart1
{
public class VisualWebPart1 : WebPart
{
protected const string _ascxPath = @”~/_CONTROLTEMPLATES/SimpleWebPart/VisualWebPart1/CustomUserControl.ascx”;
public VisualWebPart1()
{
}
protected override void CreateChildControls()
{
try
{
Control control = this.Page.LoadControl(_ascxPath);
Controls.Add(control);
}
finally
{
base.CreateChildControls();
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
}
}
3. Next we will add the user control in our webpart solution so that it gets deploy along with the webpart.
4. Next right click on the project and navigate to “Add -> SharePoint Mapped Folder”.
5. In the popup select TEMPLATE -> CONTROLTEMPLATES.
7. Once done you will see a new CONTROLTEMPLATES added to your project solution. You can now add your control CustomUserControl.ascx in your control templates folder.
8. Next press F5 to deloy the project.
9. Verify in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES location for your custom control CustomUserControl.ascx
Ads by Google
No comments:
Post a Comment