Home Dashboard Directory Help

SharePoint 2010 Visual Web Parts Missing .ascx.g.cs In Visual Studio 2012 by Derek Miller (Uber)


 as Not Reproducible Help for as Not Reproducible

Sign in
to vote
Type: Bug
ID: 766021
Opened: 10/3/2012 8:02:27 PM
Access Restriction: Public
User(s) can reproduce this bug


It appears that the old issue in VS2010 where the .ascx.g.cs file does not generate after a certain number of characters in the .ascx file is reached, is back in VS2012.

Create a visual web part project (appears to be an issue in both sandboxed and farm projects). Start adding controls to the user control.
After a certain point, the designer stops generating the .ascx.g.cs file and the project will not build as the code cannot see the InitialiseControl method or any of the controls definewd in the user control.

So now it is NOT POSSIBLE at all to implement a Visual Web part for SP2010 in Visual Studio 2012.

Sign in to post a comment.
Posted by Labhesh Shrimali on 8/10/2013 at 3:10 AM

Install Visual studio 2012.
create sharepoint project and under that create webpart,
the bug is reproduced.
Cheers !
Posted by Zerg00s on 8/9/2013 at 2:33 PM
One of my colleagues had the same problem yesterday. I thought it was just a random bug. However, When I came home and tried to create a fresh Visual Web part as a test, it turned out that ascx.g.cs file is not generated at all. I have installed 11.0.60610.01 Update 3 in Visual Studio 2012. I have disabled all Extensions, just in case. And yes, I would not really close this bug... I have no idea how to create a Visual Web part now.
Posted by MaartenSundman on 3/6/2013 at 2:23 PM
This issue has returned again in the RTW of the Office 2013 Visual Studio 2012 Dev Tools released 2/26. This had been resolved in the preview bits.
Posted by Labhesh Shrimali on 3/5/2013 at 7:32 AM
Hi, when I am making my visual webpart multilanguage that is : when adding $Resource:filename,key in the .ascx file, the webpart starts complaining.

The issue still available. let me know if someone has this sorted out.
Posted by Ben Stegink on 1/10/2013 at 11:06 PM
I experience this same bug, however in my case it isn't due to a certain number of characters, but adding <%@ Register %> or <% Assembly %> to my .ascx file immediately clears the .ascx.g.cs file. I have been able to consistently replicate this on two different SharePoint servers.
Posted by Microsoft on 1/8/2013 at 6:41 PM
Hi Derek,

We are unable to reproduce the issue. We ran several tests in our latest builds and failed to reproduce the error.

Please install the latest updates to Visual Studio and Office Developer Tools.

Chakkaradeep Chandran, Program Manager, Visual Studio SharePoint Tools
Posted by D0d1us on 11/11/2012 at 9:14 AM

did you managed to solve it?
for some reason ascx.g.cs - is not generated and I'm constantly receiveing:

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

have try from scrach... few time it works on absolutey clean project, but then fails again.
Ver. 11.0.50727.1 RTMREL
Posted by Microsoft on 10/29/2012 at 2:15 PM
Hi Derek,

Thank you for your feedback. We were not able to reproduce this issue in our latest builds. Please verify this bug again with our next release and reactivate this bug if necessary.

Chakkaradeep Chandran,
Program Manager, Visual Studio SharePoint Developer Tools
Posted by Microsoft on 10/3/2012 at 8:52 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Zerg00s on 8/9/2013 at 2:49 PM
You can recreate a project and there everything will be fine. Not a great solution, though.
Posted by Labhesh Shrimali on 3/5/2013 at 11:39 PM
Today I encountered a weird issue, the classic Visual Web Part template was gone in Visual Studio 2012. When I created a Visual WebPart, a webpart was created with a generated .g.cs file, like the sandboxed visual webparts. I am not exactly sure why it happened. According to the MSDN guide Creating Web Parts for SharePoint, the structure of Visual Webparts should be the same as in Visual Studio 2010. It could have happened after I installed the power tools.

However, if someone runs into the same issue, here is the solution:

Copy this zip file from a computer with VS2010 installed:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\SharePoint\SharePoint14\1033\SharePoint14VisualWebPart.zip
Unpack it.

Edit SharePointVisualWebPart.vstemplate. Change the assembly line so it references to the Version 11:

After that copy the directory SharePoint14VisualWebPart to these two locations on your computer with Visual Studio 2012 installed.

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplatesCache\CSharp\SharePoint\SharePoint14\1033\
Just to be safe, save the SharePoint14VisualWebPart (which have the same name) by appending “.bak” to the name.

Tx to the post: http://chuvash.eu/2012/09/20/the-original-visual-web-part-template-is-missing-in-visual-studio-2012/

File Name Submitted By Submitted On File Size  
SharePoint14VisualWebPart.zip 3/5/2013 4 KB
SharePoint14VisualWebPart.zip 8/10/2013 4 KB