• .ascx.g.cs文件不能生成 The name ‘InitializeControl’ does not exist in the current context


    InitializeControl doesn't exsit


    When using visual studio 2012 for developing SharePoint 2013 Visual web parts either of type sandbox solution or farm solution you might face a the following error:

    “The name InitializeControl” does not exist with the current context


     

    Before describing the solution lets first describe the error, as shown in the image above this error occurs on the OnInit Method.

    About OnInit: OnInit method is part of the web part life cycle, which is responsible for initialization the controls inside the web part (as example label, button, textbox and others).

    By mapping between the error and the OnInite method you will realize that this issue relates to controls inside the web part.
    By checking the visual web part, I found that the designer file of type “ascx.g.cs” is missing, this file is responsible for drawing the controls that are mapped with the visual web part.

     


    This issue could occur by two reasons, as follows

    1.The solution is not using an existing or valid URL, by checking the SharePoint URL please make sure that the URL is valid and exists, try to map the URL and build your solution and check the result if the error still exists.
     
    2.If the error still exists and the URL you are using is correct then we will do some manual steps on top of visual studio as follows


    a.Right click on you SharePoint project and then add new item


    b.Add user control as shown below, its better to name this user control by the same name of your visual web part, as example if your web part called Visual Web part 1, then for the User control name it as Visual Web part 1
     

     

     
    c.The user control will resides under the ControlTemplates folder (Mapped folder) as shown below


     

    d.Under the visual web part “VisualWebPart1” make sure to delete the “VisualWebPart1.ascx” as shown below

     


     

    e. Then we will drag the VisualWebPart1.ascx that resides in the ControlTemplates folder and drop it under the VisualWebPart1 , this will add the new user control including its designer under the VisualWebPart1, your solution should look like below





    f.   Now try to add “Label” as example and build your solution, the result is great and the error has gone.


    The Question is: do we need to repeat same steps for any new visual web part?
    The answer is No, simply you can remove the old web part , then add a new visual web part and the Visual Studio will automatically create the “ascx.designer.cs” file for you ,so consider your visual was stuck but then it works properly.

    referring to:http://samer-othman.blogspot.com/2013/03/how-to-fix-error-name-initializecontrol.html


  • 相关阅读:
    docker建镜像
    注册路由的简易实现
    docker的小技巧记录(如果使用了更多会继续添加)
    Alembic使用
    SQLAlchemy的常用数据类型
    记录SQLAlchemy的基本使用
    linux创建桌面快捷方式
    vim编辑器命令
    redis发布订阅
    谨慎使用mysql的utf8
  • 原文地址:https://www.cnblogs.com/kinpauln/p/3287614.html
Copyright © 2020-2023  润新知