none
The name 'InitializeControl' does not exist in the current context

    Question

  • Hi all , 

    i am having visual studio 2012 sp1. 

    I am getting build error ( The name 'InitializeControl' does not exist in the current context )

    when i removed all lines that uses the resources , the solution build successfully.

    any idea how to solve this ?! 


    Thanks Mohd Al-Bakri

    Wednesday, December 19, 2012 4:18 AM

All replies

  • Hi Al,

    What project did you create and what language did you use?

    I found a blog talking about this issue which you can refer to:

    http://blog.mastykarz.nl/the-name-initializecontrol-does-not-exist-in-the-current-context-visual-web-part-sandboxed-bug-fix/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+WaldekMastykarz+%28Waldek+Mastykarz%29

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 20, 2012 5:56 AM
  • thanks for answering ,,

    Its C# SharePoint 2010 project with farm deployment.

    and i test the blog  it did not help in my case ,, :/


    Thanks Mohd Al-Bakri

    Thursday, December 20, 2012 7:51 AM
  • Hi,

    Based on your project is SharePoint 2010 project, I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
     
    Thank you for your understanding and support.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 21, 2012 6:00 AM
  • Did you find any solution to this? I am facing the same error when using a UserControl in the webpart in VS 2012 too !!
    Monday, December 24, 2012 7:00 AM
  • Did you find any solution to this? I am facing the same error when using a UserControl in the webpart in VS 2012 too !!
    I have the same error. :(
    Tuesday, December 25, 2012 6:02 AM
  • Try This Link....

    http://blog.mastykarz.nl/the-name-initializecontrol-does-not-exist-in-the-current-context-visual-web-part-sandboxed-bug-fix/

    Tuesday, December 25, 2012 6:26 AM
  • i found a solution and its worked for me for only 1 day i dont know what is wrong with the VS. so i think the  issue with my environment

    replace all the resources you have by the following format

    Text='<%$ Resources:[TMS.UI,]TM_AddNewTask_lblTaskTitle %>'

    note the spaces between ($ R) and (e %),, and note also the [    ,].

    its worked , the day after that it did not , i had rebooted the server. i back to the same error. 

    I switch to VS 2010 SP1. i already spent 2 days. 

    please any one verify if the above worked for him. 


    Thanks Mohd Al-Bakri

    Tuesday, December 25, 2012 2:00 PM
  • I am using VS2012,and work on SharePoint2013 Visual WebPart. So it dosn't work.   :(

    Hi TecTeng,

    Please post your question in SP 2013 forum. This is SP 2010 forum and i am going to delete your post now.

    thanks for your support


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Saturday, December 29, 2012 6:35 AM
    Moderator
  • hey man , sorry i forgot to tell you after you use you need to make sure that the resource key already exist in the resource file that attache do the solution , then copy past it to the iis App_GlobalResources file , then also copy it to the 14 resources in your case will be 15. then build the solution. 

    Thanks Mohd Al-Bakri

    Sunday, December 30, 2012 5:00 AM
  • Hi Mohd Al-Bakri,

    >please any one verify if the above worked for him. 

    Is this solution worked for you? If yes then please close your thread by marking an answer which helped you. since this thread is started by you so you need verify whether it works for you or not.

    Thanks for your support


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Sunday, December 30, 2012 5:21 AM
    Moderator
  • nop i did not , i mentioned that i went back to use VS 2010 sp1. but the solution was worked for me for a while then after restart it comes back.


    Thanks Mohd Al-Bakri

    Sunday, December 30, 2012 11:39 AM
  • in standard way, when you try to add UserControl to some SP2013 web part by drag-n-drop method it register reference for that user control, and it looks like this:

    <%@ Register Src="~/_controltemplates/15/MySolution.ProjectTitle/PropagateDesign.ascx" TagPrefix="ucc" TagName="SomeUserControlName" %>

    and it's not working.

    In order to make it work, you just need to change way of registering references for that user control like SharePoint does, and in my case it looks like this:

    <%@ Register TagPrefix="ucc" Namespace="MySolution.ProjectTitle.ControlTemplates.MySolution.ProjectTitle" Assembly="MySolution.ProjectTitle, Version=1.0.0.0, Culture=neutral, PublicKeyToken=de6ba60f3bca4edd" %>

    last part of references (Assembly) you can find in web.config file of your SP application

    with this kind of registration you will be able to have one registration line and to list all UserControls from that namespace


    COOL SOLUTION => enjoy



    Sunday, April 21, 2013 11:41 AM
  • Not sure if anyone is still having this issue, I resolved mine by "tricking" VS.net into doing a clean build of file.ascx.g.cs

    I had a similar issue - mine happened in VS2012 for SP2010 when I manually deleted obj, pkg, etc... folders... Looks like the code behind doesn't generate successfully, so I had to change

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="file.ascx.cs" Inherits="project.webpartnamespace.class" %>

    to

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="file.ascx.cs" Inherits="project.webpartnamespace" %>

    then rebuild - to get a single error that class already defined, and then back to:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="file.ascx.cs" Inherits="project.webpartnamespace.class" %>


    Armine Bell

    Wednesday, July 31, 2013 5:47 AM
  • Hi,

    For me the solution was to make sure the project property 'Site URL' was set to a valid SharePoint Web Application URL.

    Cheers,
    Vincent


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 01, 2013 5:49 AM
  • That's correct some assembly reference is incorrect and the ascx.gs.cs will be empty. which means you will get initalizecontrol error

    Thanks

    Thursday, October 10, 2013 9:42 PM
  • I face the same issue. So, close VS and then Run as administrator, it works for me
    Tuesday, December 10, 2013 9:59 AM
  • After done an analysis i have identified, it is the permissions related issue for that purticular web application content DB. For generating ascx.g.cs file user need  owner access for that contentDB.

    Monday, January 06, 2014 1:07 PM
  • The common issue seems to be the ascx.g.vb (or cs) file doesn't get generated if the connection to the SharePoint environment wasn't successful.  Double check the Site Url under project properties, make sure it's accurate, then right click on your VisualWebPart1.ascx (or whatever name you have) and choose "Run Custom Tool".  I know that there are many causes to this issue, but from my work in SharePoint 2010 and 2013 this tends to be a more common fix than some of the others.  Hope you find your solution!
    • Proposed as answer by zvgould191 Wednesday, April 16, 2014 10:18 PM
    Friday, January 31, 2014 10:15 PM