If you develop web parts in Visual Studio 2012 for Sharepoint 2013, you may notice that now for each web part VS creates files differently, then in VS2010 and Sharepoint 2010:
- ascx file – contains layout of web part;
- ascx.cs – contains partial class with your code;
- ascx.g.cs – contains automatically generated partial class, which contains code representation of layout from ascx file.
The main difference with VS2010 is that automatically generated file contains all initialization code for all elements in ascx, not just declaration of protected controls (like ASP.Net does when request goes to aspx files). With this approach it is not needed to copy ascx files to ControlTemplates folder, because all web part code is now compiled into the assembly. With this approach it is easier to develop web parts for O365 sites.
There is one bug in VS2012: when you try to change ascx file for web part automatically generated ascx.g.cs file is deleted. In order to avoid this problem you need to specify url of the correct Sharepoint site in “Site URL” for the project with the web part in VS:
Seems like VS tries to connect to Sharepoint site, when you change ascx file.
Note that if you use host headers for your sites on local dev environment, then it is necessary to add these host headers to your hosts file:
Otherwise when you will try to save “Site URL”, you will see error “Remote SharePoint site connections are not supported”:
Hope that it will help you if you will encounter with this problem.