Visual Web Part in VS2012, code in ascx.g.cs is erased - by Ben Stegink

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 776340 Comments
Status Closed Workarounds
Type Bug Repros 6
Opened 1/11/2013 8:20:27 AM
Access Restriction Public


Creating a new SharePoint 2010 Visual Web Part in Visual Studio 2012.  Add <%@ Register %> to the .ascx file and all the code is erased deleted from the .ascx.g.cs file.
Sign in to post a comment.
Posted by SteveCl on 10/29/2013 at 8:11 AM
Check that the Assembly and Namespace are deployed to SharePoint first before adding the register tag.

As MS said, VS communicates with SP to build that ascx.g.cs file, so if it can't find your assembly and namespace it will cause an error.
Posted by JeffreyJa3 on 9/15/2013 at 8:50 PM
Unfortunately the workarounds do not work in my case.

I have opened a new Feedback thread here:
Posted by Shannon Ewing on 7/19/2013 at 8:17 AM
To easily reproduce, add a literal control to the ascx, add a reference to a resource for the text (e.g. Text="<%$Resources:MyResourceStuff, Email %>" ) to the control. All contents of the .ascx.g.cs get blow away. Now simply remove that Text attribute. The contents of .ascx.g.cs return.
Posted by Shannon Ewing on 7/19/2013 at 8:01 AM
I can confirm what Dan Attis noted. Just ran into this. In our case adding a <%Resources:.. tag seemed to blow away everything in the .ascx.g.cs file AND we just installed release 3.
Posted by Dan Attis [MVP] on 7/2/2013 at 9:50 AM
Why is this bug closed? If it's by design, why is there no workaround posted? I cannot complete my web part. This was working fine in VS 2012 release 2, but seems to have manifested itself again in release 3.
Posted by JeffreyJa3 on 6/25/2013 at 12:45 AM
And again, I am having the same issue.

I am not sure if it is related to the <%@ Register %> tags I have in my webpart or the amount of code that is in the webpart but when I remove either the <%@ Register %> tags or reduce the code in the webpart the ascx.g.cs file once again regenerates itself automatically.

A fix would be really great as this is stopping me from completing 2 webparts.
Posted by Vasyl Viyatyk on 5/15/2013 at 8:00 AM
Hi Guys
I have had the same issue.
in one case there were two equal attributes in the tag.
in other case attribute <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> was without space in the end of line. (<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$"%>)
Posted by matifimran on 4/8/2013 at 3:57 AM
I am facing the same issue while using Telerik controls in webparts. Any fix available for this issue?
Posted by W0uter on 2/18/2013 at 4:25 AM
I have the same issue.

When saving a visual webpart ascx file the ascx.g.cs file is deleted from the hard drive. The references to the file in the project file are also deleted. Nu actual change to the ascx is needed. I do ctrl+s in the ascx and the acsx.g.cs files is gone.

Visual Studio 2012. SharePoint 2013 project. Disabled 3th party plugins.
Posted by Microsoft on 1/17/2013 at 11:19 AM

Thanks for the feedback. Can you complete the <%@Register %> tag with all the required attributes and then check whether the VisualWebPart.ascx.g.cs file? Visual Studio communicates with SharePoint to generate the VisualWebPart.ascx.g.cs and will not be generated if there are any errors or if SharePoint is not able to resolve something in the VisualWebPart file.

Chakkaradeep Chandran, Program Manager, Office Developer Tools
Posted by Microsoft on 1/13/2013 at 11:17 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 1/11/2013 at 8:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(