.ascx.g.cs文件不能生成 The name ‘InitializeControl’ does not exist in the current context - Visual Web part Sharepoint
2013-08-28 17:21
253 查看
InitializeControl doesn't exsit
When using visual studio 2012 for developingSharePoint 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.
[align=left] [/align]
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
相关文章推荐
- To deploy the Web Part(Cab Files) to SharePoint Server 2007(Sharepoint 2007 SDK)
- 转:Creating a SharePoint Visual Web Part using Visual Studio 2010
- Making the Newsfeed web part available outside of My Sites in SharePoint 2013 分类: Sharepoint 2015-07-07 19:29 4人阅读 评论(0) 收藏
- Use the Picture Library Slideshow Web Part in the SharePoint 2010
- Making the Newsfeed web part available outside of My Sites in SharePoint 2013
- 如何打印SharePOint 一部分,而不是整个页面Printing just the web part and not the entire SharePoint page
- SharePoint At Work----Hyperlinks in the Data View Web Part
- SharePoint At Work----Hyperlinks in the Data View Web Part
- SharePoint WEB应用程序下的Web.config文件出错导致网站不能打开
- [Forward]Use the SharePoint My Tasks Web Part outside of My Sites
- Content Query Web Part VS the Content Search Web Part in SharePoint
- 工具:sharepoint webservice:根据asmx生成disco和wsdl文件
- Using the SharePoint 2010 Client Object Model_part_5
- Openning SharePoint - 80 website gives HTTP 404 Error, The webpage cannot be found ! on SharePoint 2013
- VS 如何自动生成 aspx.designer.cs文件内容(解决"The base class includes the field ''"错误)
- visual web developer 2008 调试时:无法启动程序 “http://localhost/xxx不能调试”.系统找不到指定的文件.
- Using the SharePoint 2010 Client Object Model_Part_6
- 创建web项目不能生成web.xml文件
- SmartPart v1.0 for SharePoint [Free Web Part]
- SharePoint excel service web part 连接到 filter web part