INTRODUCTION
In Visual Studio 2010 you can create a Visual Web Part (ie. web part that renders ASCX file). In VS 2010 when you create a Visual Web Part, VS 2010 automatically creates a module that contains the following files:
– Web part class (UserProfileListing.cs below)
– ASCX and code behind
– Elements.xml file
– .webpart file
See below for example:
In Visual Studio 2012 however, the following files don’t exist:
– Web part class
See below:
Rather, the .webpart file references the ASCX code-behind class name directly. And if you open the package file, the ASCX is also not included meaning that your ASCX will not be deployed as part of the WSP file. See below:
This is not working properly for me.
WORKAROUND
The workaround is:
– Create a separate user control that lives in /_CONTROLTEMPLATES.
– Create a class that references Microsoft.SharePoint.WebPartPages.WebPart
– Point your .webpart to the custom class you just created, such as below:
<?xml version=”1.0″ encoding=”utf-8″?>
<webParts>
<webPart xmlns=”http://schemas.microsoft.com/WebPart/v3″>
<metaData>
<type name=”XXX.SP.Quickpoll.Quickpoll.Quickpoll, $SharePoint.Project.AssemblyFullName$” />
<importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
</metaData>
<data>
<properties>
<property name=”Title” type=”string”>Quickpoll</property>
<property name=”Description” type=”string”>The Quickpoll web part.</property>
</properties>
</data>
</webPart>
</webParts>
– Then finally in your custom web part class load the ASCX file:
protected override void CreateChildControls()
{
ControlTemplates.XXX.SP.Quickpoll.Quickpoll control = Page.LoadControl(“~/_CONTROLTEMPLATES/XXX.SP.Quickpoll/Quickpoll.ascx”) as ControlTemplates.XXX.SP.Quickpoll.Quickpoll;
Controls.Add(control);
}
The easiest way is to refer to your Visual Studio 2010 Visual Web Part module template.
Hope this helps,
Tommy
We provides you the best Services in our themes.
Click on the link below to see a full list of clients which we have developed solutions and provided consultancy for.
We are solution-centered and not application-centered.
Being creative and having fun and yet still delivering a fantastic service is the center of our values.
TFS Consulting Services guarantees delivery that is within budget and deadline or you engage us for free.
Implementing IT solution does not have to be difficult. TFS Consulting Services has a lot of resources on planning and methodologies that will ensure successful delivery of your IT solution. TFS Consulting Services has been around in the web industry for more than 10 years and has experienced all the successes and failures of various type of IT deployment.
Do you need a technical resource? TFS Consulting Services can also provide you with technical resource for developing ASP.NET (C# and VB.NET), SharePoint (2003, 2007, 2010, 2013) and MS CRM applications. Our resource is an Microsoft Certified Personnel (MVP) and Microsoft Certified Technology Specialist (MCTS) in all ASP.NET, SharePoint and CRM.
Make sure your IT implementation is robust and scalable. TFS Consulting Services can provide consulting and advice on industry’s best practice on various web-related areas such as website security, design and usability, application-specific (such as SharePoint)’s best practice, Search Engine Optimisation (SEO), coding standards and many others.
Finally TFS Consulting Services provides you with solution development service. We mainly work with Microsoft technologies (ie. .NET and SQL Server), however we are also capable of developing with PHP and MySQL. If you ever need any business process automation, integration and solution development work, we are the trusted expert you should go to.
For more detailed service offerings please visit our Solutions page.
Tommy Segoro
tommy@tfsconsulting.com.au
+61 404 457 754
© TFS Consulting Services 2024. All rights reserved.