Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
2.2k views
in SharePoint Server by 13 13 19
edited by

I have a SharePoint 2013 farm, I created a new SharePoint solution as a sandbox solution and I can add a visual web part as a new item that was added successfully.

add new visual web part in sharepoint 2016 solution

When I built the solution, I faced this error.

Error 2 The name 'InitializeControl' does not exist in the current context
c:\users\awis\documents\visual studio 2017\Projects\SharePointProject\SharePointProject\VisualWebPart1\VisualWebPart1.ascx.cs

The name 'InitializeControl' does not exist in the current context in SharePoint 2016

How I can fix this error "The name 'InitializeControl' does not exist in the current context in SharePoint 2013"?


1 Answer

2 like 0 dislike
by 159 200 385
selected by
 
Best answer

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

This kind of Visual WebPart is supported in SharePoint 2013 Sandbox solution. and actually, I can't regenerate your error on my side.
So I would suggest doing the following:

  1. if it's a new Visual WebPart. try to delete it. (take a backup from the solution before deleting).
  2. Save your changes and restart Visual Studio as Administrator.
  3. In Project Properties, set the SandBox solution to false (Or create a new SharePoint Project deployed as Farm Solution)
    Switch sandbox solution to farm solution
  4. Readd a new Visual WebPart (Farm Solution Only), not a Visual WebPart.
    Create Visual WebPart (Farm Solution Only)

Code-based sandbox solutions are deprecated in SharePoint 2013 and in SharePoint 2016. Read also The Resource does not exist in the current context


See Also

by 13 13 19
0 0
Hi Mohamed, using the visual web part with farm solution only, solved my error! Thanks for your help!
If you don’t ask, the answer is always NO!
...