Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created a visual webpart from VS2012. The headers of the ascx page are

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyVisualWebPart.ascx.cs" Inherits="MySPSolution.WebParts.MyVisualWebPart.MyVisualWebPart" %>

later in the code i have

<asp:Label ID="Label1" runat="server" Text="<%$Resources:MyResources,Title%>" />

The problem is that when i use the <%$ there is a build error says

The name 'InitializeControl' does not exist in the current context

It's not that it doesn't find a key in MyResources. It doesn't compile at all. By the way MyResources is in App_GlobalResources folder, and the same usage works in an aspx page.

What i am doing wrong?

share|improve this question
    
Is the .designer.cs / g.cs file still generated correctly? Your issue seems similar to a behavior caused by a bug that trigger an "empty" designer file. Try to confirm that all the visual web part files have the expected content. –  SPArchaeologist Apr 8 '13 at 8:40
    
You are right g.cs file is empty. Can i fix it? –  pbaris Apr 8 '13 at 9:18
    
Gotcha! Please - see if your issue is the same described in this answer. If that's the case, you can upvote that answer. –  SPArchaeologist Apr 8 '13 at 10:26
    
Also, even if the solution in the above link does not work for your case, the empty g.cs file is probably the cause. We "just" need to understand why it is empty. Any sign of error in the .ascx file? Red underline, warning or such? –  SPArchaeologist Apr 8 '13 at 10:30
    
no i don't think that it is the length of the contents. After the 8 lines of header i have an empty line and then a line with the <asp:Label ... /> tag –  pbaris Apr 8 '13 at 10:35
show 1 more comment

1 Answer

up vote 2 down vote accepted

I believe I have found it.

As of today 8 april 2013 this seems to be a bug with the current version of Visual Studio 2013 and SharePoint 2013 developer tools.

This link points to the original Connect discussion: here. All context match: attempt to use a resource in the .ascx file, empty g.cs file, error message...

Hello, I am running VS Ultimate 2012 11.0.51106.01 Update 1 with the SharePoint Developer Tools Preview 2. I've been trying to build a localized SharePoint Visual Web Part but I am getting the infamous 'The name 'InitializeControl' does not exist in the current context' error when trying to reference a project resource file in the user control's ASCX source. The ascx.g.cs file subsequently becomes blank and the project no longer compiles. How can resource files be used inside an ASCX control with the new 2012 Visual Web Part? Thanks in advance for your help, Raphael.

As you can see the reporting user seems to have the same error. See the discussion in the original connect link and also here. Seems that the current workaround is to set the resource via code behind. Part of a grand plan to have only one resource system (instead of the 14 resource + app_globalresources) it seems, but until they complete the plan we will have to live with it.

share|improve this answer
    
i am trying to update to VS2012 Update 2, Tools RTM as 'Vincent BIRET' suggested in the second link you provided. I'll let you know –  pbaris Apr 8 '13 at 11:20
    
The update didn't fix the problem. I will try code behind now –  pbaris Apr 8 '13 at 11:51
    
@pbaris ok. If you are in an urge to fix that, also consider localizing the label via code behind. It isn't optimal IMHO, but from what we have gathered so far, it would seem that your error IS caused by the resource usage in the ascx file... so not many choices there. –  SPArchaeologist Apr 8 '13 at 11:53
    
Yes code behind worked. Not the best solution but till the fix... –  pbaris Apr 8 '13 at 12:02
    
Look - If the error is given by the <%$Resources usage, removing it is bound to fix the problem. Now, ensuring that the issue is caused by the above bug would be harder. Still, all evidences point to a common problem... so I assume you have no choice. Glad you sorted it for now. –  SPArchaeologist Apr 8 '13 at 12:59
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.