Widgets written in Sitefinity don't compile in VS 2013
I'm working on a Sitefinity website were a lot of the custom widgets were built inside Sitefinity and not in Visual Studio. They are a Mac shop and writing the c# code from an editor. Now they brought me in to help them get some services working, but I can't compile because I get the error message:
The name [Control Name] does not exist in the current context.
I'm not sure why I'm getting this as the control is in the ascx file just like it should be. Something's wrong because when I try to write my own widget using Thunder the templates are very different than these already written controls
Here's the brand-hero.ascx file
01.<%@ Control Language="C#" AutoEventWireup="true" CodeFile="~/Custom Widgets/BrandHero.cs" Inherits="SitefinityWebApp.ProductWidgets.BrandHero" %>02.<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.DynamicModules.Web.UI.Frontend" TagPrefix="sf" %> 03.<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" TagPrefix="sf" %> 04.<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %> 05.<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Comments.Web.UI.Frontend" TagPrefix="sf" %> 06.<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Libraries.Web.UI" TagPrefix="sf" %> 07.<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.PublicControls" TagPrefix="sf" %>08.<%@ Import Namespace="Telerik.Sitefinity.Web.UI" %>09.<%@ Import Namespace="Telerik.Sitefinity.Modules.Comments" %>10.<sf:SitefinityLabel id="title" runat="server" WrapperTagName="div" HideIfNoText="true" HideIfNoTextMode="Server" CssClass="sfitemFieldLbl" />11.<asp:Repeater id="detailContainer" runat="server">12. <ItemTemplate>13. <div class="sfitemDetails sfdetails brandHero clearfix"14. data-sf-provider='<%# Eval("Provider.Name")%>' 15. data-sf-id='<%# Eval("Id")%>' 16. data-sf-type="Telerik.Sitefinity.DynamicModules.Model.DynamicContent" 17. style='background: Url('<%# Eval('HeroImage.Url') %>');'>18. <div class="logo"><img src="<%# Eval("Logo.Url") %>"/></div>19. <div class="middleContent">20. <div class="description"><%# Eval("BrandMessage")%></div>21. <div class="socials">22. <a href="<%# Eval("Facebook")%>" class="symbol"></a>23. <a href="<%# Eval("Twitter")%>" class="symbol"></a>24. <a href="<%# Eval("GooglePlus")%>" class="symbol"></a>25. <a href="<%# Eval("YouTube")%>" class="symbol"></a>26. <a href="<%# Eval("Link")%>" class="link">GO TO <%# Eval("Link")%></a>27. </div>28. </div>29. </div>30. </ItemTemplate>31.</asp:Repeater>
And here's the code behind brand-hero.cs
01.namespace SitefinityWebApp.ProductWidgets 02. 03. public partial class BrandHero : System.Web.UI.UserControl04. 05. protected override void OnInit(EventArgs e) 06. 07. base.OnInit(e);08. 09. var dynamicModuleManager = DynamicModuleManager.GetManager();10. Type brandType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Brands.Brand");11. 12. string urlParams = this.GetUrlParameterString(true);13. string selectedBrand = "";14. 15. if (String.IsNullOrEmpty(urlParams)) 16. // No Params, 40417. else 18. 19. // Parse URL params20. string[] querySegments = urlParams.Split('/');21. if(!String.IsNullOrEmpty(querySegments[1])) 22. selectedBrand = querySegments[1];23. RouteHelper.SetUrlParametersResolved(true); // this prevents 40424. 25. 26. // check if Brand is valid and get it27. var brand = dynamicModuleManager.GetDataItems(brandType).Where(b => b.UrlName == selectedBrand && 28. b.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);29. detailContainer.DataSource = brand;30. detailContainer.DataBind();31. 32. 33. 34. 35. 36. 37. 38.Hi John,
The reason why your code behind does not recognize your controls is due to the lack of a behind brand-hero.designer.cs in your solution. This designer is responsible for mapping the controls to the codebehind. In general the designer.cs should be generated automatically when you create a control in a Visual Studio web application such as Sitefinity. This leads me to believe the controls you have developed were made inside a web site, not a web applicateion. if this is the case and you do not have any designer files, you can regenerate them easily by right clicking on the ascx file and selecting "Convert to Web Application".
Regards,
Ivan D. Dimitrov
Telerik