I recently found during my deployment that once of my visual web part's ascx content is not updated in the staging environment when I deploy wsp!
So, I started searching for my ascx file in 14 hive but did not find it anywhere. That became really frustrating when I was not able to find ascx file in my local farm's 14 hive as well! I did some google searching for g.cs and most of the results were either complaining about "can not find Initialize control" or they got a blank g.cs file!
Then I went ahead and looked into the source code for the g.cs file and I found that for each of your control in ascx, its actually generating elements. For static content, its concatenating to string variable and for all server controls, its generating code and setting properties. I recall doing same in classic web parts without ascx controls and my question was answered.
So, g.cs file is c# version of your ascx code so that it doesn't have to deploy ascx control in file system but instead works just like a classic web part!
Well, in that case, it should work as sandbox solution as well, right? I did not tried it but ideally yes if your code is following limitations for sandbox solutions.
Now the original problem was:
In our organization we use source control system. Upon pull, I got conflicts and I correctly merged ascx file but not properly merged g.cs file considering its useless and visual studio automatically handles it when I will open project.
But that wasn't true. After doing this, when I publish/deploy my wsp, visual studio will not regenerate that file again on build/publish/deploy. It only generates g.cs file again when you hit save in ascx control. That was the answer of my problem.
So, never ignore ascx.g.cs files in your solution, always make sure you merge g.cs files OR after every conflict you hit save in your ascx to regenerate ascx.g.cs file again! That's what I conclude.
I hope this will be helpful to you all!