“The name ‘InitializeControl’ does not exist in the current context” Error (SharePoint 2010)

I recently started to work on SharePoint development, and have been playing around with SharePoint 2010 Web Part Development on Visual Studio 2010.

For this, I acquired a machine image from a friend of mine (temporarily, just for trial purposes) with Windows Server 2008 R2, Visual Studio 2010 Ultimate, SharePoint Server etc. all set up already.
Then I created an empty SharePoint project, added a Visual Web Part (Sandboxed). Everything is quite easy and straight forward, right? I added some controls in the designer window then opened the code file for my web part, say “VisualWebPart1.ascx.cs”.
Then I saw it!! That ugly, red underline below “InitializeControl” method within “OnInit” method.

Error Message says “The name 'InitializeControl' does not exist in the current context“.

Along with it you will also see that there is no designer file created for this web part, which is supposed to be named as “VisualWebPart1.ascx.g.cs” and placed right under “VisualWebPart1.ascx.cs” file.
I made some research on the internet. Some solutions mentioned installing SP1, I did that and still no luck.
For my case the problem was the debugging URL of my “project”. When creating a new SharePoint project you need to choose a URL for debugging your project as the “SharePoint Customization Wizard” screen below requires.
Problem was that the URL value in “What local site do you want to use for debugging?” field was no longer valid because apparently that default value was coming from a previous project which was deleted and no longer existed. (At least this is what I understand from what my SharePoint specialist friend told me)
I created a new project and changed this invalid URL to a new valid one (like http://win2008/, which uses port 80 by default) and everthing was okay.

Seems like this is a bug to be fixed. I would expect Visual Studio to check if that URL is valid, and if not warn me with a message.

Hope this helps someone.

Good luck,
Serdar.

4 thoughts on ““The name ‘InitializeControl’ does not exist in the current context” Error (SharePoint 2010)

  1. Quality posts is the main to attract the people to
    go to see the site, that’s what this website is providing.

  2. Great goods from you, man. I have understand your stuff prior to and you are simply too great.
    I really like what you’ve obtained here, really like what you’re saying and the way in which through which you are saying it.

    You make it enjoyable and you still care for to stay it smart.

    I can’t wait to learn much more from you. That is really a great site.

Leave a Reply

Your email address will not be published. Required fields are marked *