Home Dashboard Directory Help
Search

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


Status: 

Closed
 as By Design Help for as By Design


16
0
Sign in
to vote
Type: Bug
ID: 776340
Opened: 1/11/2013 8:20:27 AM
Access Restriction: Public
2
Workaround(s)
view
6
User(s) can reproduce this bug

Description

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.
Details
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: https://connect.microsoft.com/VisualStudio/feedback/details/800844/webpart-control-stops-creating-amending-the-ascx-g-cs-file
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
Hi,

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.

Thanks,
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(http://support.microsoft.com)
Sign in to post a workaround.
Posted by sadomovalex on 8/17/2013 at 10:59 AM
Specify url of correct Sharepoint site in "Site URL" property of your project.
Posted by sadomovalex on 8/17/2013 at 10:56 AM
Wrote about workaround here: http://sadomovalex.blogspot.com/2013/08/fix-bug-in-visual-studio-2012-with.html. You need to specify url of correct Sharepoint site on local dev environment.