4

I am encountering this error when I create a visual web part in Visual Studio 2012:

the name 'initializecontrol' does not exist in the current context visual studio 2013 

Edit 1: the error appears in this line of code in .ascx.cs file:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    InitializeControl();
}

And there is no .g.cs file.

I have seen some blogs or posts, but they are not helping me with this issue. I have installed Updates 4 for visual studio. Hope to hear from you guys.

  • Is there a markup error in your aspx file? Does your .g.cs file exist and have content? – Sam Sussman May 2 '14 at 13:02
  • I just updated my post. Please have a look at Edit 1. There is no .g.cs file. – Imir Hoxha May 2 '14 at 13:16
  • There should be a .g.cs file or a designer.cs file. If there is not you may have an error in your markup. – Sam Sussman May 2 '14 at 13:18
  • I had this issue when i copied some code from another project. Turned out i missed to change the Inherits property (Namespece) in the ascx – George Norberg Jan 15 '15 at 14:50
  • I had turned off the connection to SharePoint, which turns off generating the .g.cs file, and when I turned it back on it still hadnt generated the .g.cs file until I had made a change to the .ascx page. – Nacht May 26 '15 at 7:15
4

I finally found one solution. It has all to do with the url of the site. It should be a valid url. It is a bit strange though because the url that I was providing was valid. To test it I created a new webapp with a site collection eg.: http://mysomething:5040 and visual web part was created successfully with the design file "....g.cs".

2

You are probably missing VisualWebpartName.ascx.c.gs file under your VisualWebpartName.ascx. Right click your VisualWebpartName.ascx and select Run Custom Tool . This will recreate .c.gs file and all errors will be gone.

0

I had a similar problem today creating a new WebPart: I renamed the default webpart name (VisualWebPart1), but VS does not rename all the code automatically, only the files, and the control reference in the ascx file was using the old ".VisualWebPart1.VisualWebPart1" reference.

I just changed the namespace to the correct one, and it worked like a charm...

0

Try to add new user control with the web part name, it will create ascx.g.cs file. This will solve the problem. You can delete the usercontrol folder later.

0

I corrected the issue, for me it occurred since i have given the Site URL as only till farm level (http://w12devt) but actually it should be URL of any site collection (http://w12devt:9999/sites/rnd).

-1

In my case it solved by adding the setting for hosts file ( The Deploy URL ) like

127.0.0.1 mysite.domain.com

  • 2
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. - From Review – Waqas Sarwar MVP Feb 24 '16 at 11:28
  • 1
    It may help someone to solve the problem , This question above , I solved it using this way – Peter Feb 24 '16 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.