I am having problem that the InitializeControls() is not working

protected override void OnInit(EventArgs e)



enter image description here

  • what is the error? Is it a webpart code?
    – Gaurravs
    Nov 16, 2015 at 6:19
  • Yes it is a webpart code and InitializeControls() cannot be found in current context. Nov 16, 2015 at 6:21
  • Can you provide a screenshot of file structure in visual studio? please provide in expanded file structure
    – Gaurravs
    Nov 16, 2015 at 6:23
  • you have written InitializeControls() instead of InitializeControl() Nov 16, 2015 at 6:25
  • Yash i have use it but still same error Nov 16, 2015 at 6:25

1 Answer 1


Few points you need to make corrections

  • InitializeControl() instead of InitializeControls()
  • You will find a ".ascx.g.cs" file once you expand '.ascx" file.
  • Change the namespace to same as in ".ascx.cs" file.
  • make sure you have same class name in both the files. Replace if it is displaying some other class name in ".ascx.g.cs" file. Replace it where ever you find it in that file.

This should be enough to get your issue resolved.

  • i cant find the ".ascx.g.cs" file once you expand '.ascx" file. Nov 16, 2015 at 6:48
  • in Visual studio, above your solution you have a search box. search for ".ascx.g.cs" in it
    – Gaurravs
    Nov 16, 2015 at 7:16
  • Do keep a copy of your code before any changes. Now Do Ctrl+Shift+ H. Enter "VisualWebPart1" in Find block & provide "EditAdvertisement" in Replace block . Hit Ok
    – Gaurravs
    Nov 16, 2015 at 7:24
  • No its not there. Nov 16, 2015 at 7:26
  • Did it worked for you?
    – Gaurravs
    Nov 16, 2015 at 7:30

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.