摘要
本篇文章将记录如何编写一个最简单的WebPart的最后一部分,即添加WebPart,包括把WebPart添加到网站的WebParts列表中,及把WebPart添加到网页中。
正文
下面将记录每一步的操作过程。
1、首先按照前面讲解过的方法打开网站的Site Settings管理主页面。
![157.Webpart.Site.jpg](http://www.oceanstudio.net/oceanstudy/denny/Images/SharePoint/157.Webpart.Site.jpg)
2、在Site Settings管理主页面中点击Web parts,即可进入Web Part Gallery管理页面。
![158.Webpart.New.jpg](http://www.oceanstudio.net/oceanstudy/denny/Images/SharePoint/158.Webpart.New.jpg)
3、在Web Part Gallery管理页面中点击New,即可进入New Web Parts编辑页面。
在New Web Parts编辑页面的Web Part列表中,找到Eallies.WebParts.Hello.Instance,并将其勾上,然后点击Populate Gallery按钮。
![159.Webpart.Add.jpg](http://www.oceanstudio.net/oceanstudy/denny/Images/SharePoint/159.Webpart.Add.jpg)
4、下面将介绍如何将WebPart添加到网页中。
打开网站首页,点击Site Actions,在弹出的菜单中选择Edit Page。
![160.Webpart.Main.jpg](http://www.oceanstudio.net/oceanstudy/denny/Images/SharePoint/160.Webpart.Main.jpg)
5、点击Edit Page页面后,页面即进入编辑状态。
![161.Webpart.Edit.jpg](http://www.oceanstudio.net/oceanstudy/denny/Images/SharePoint/161.Webpart.Edit.jpg)
6、在想要添加Web Part的地方点击Add a Web Part,即可弹出Add Web Parts对话框。
在Add Web Parts对话框中找到所需的WebPart,将其勾上,然后点击Add按钮。
![162.Webpart.Select.jpg](http://www.oceanstudio.net/oceanstudy/denny/Images/SharePoint/162.Webpart.Select.jpg)
7、添加完WebPart的页面就是这样的,看,多了一个Hello World的组件。
![163.Webpart.Added.jpg](http://www.oceanstudio.net/oceanstudy/denny/Images/SharePoint/163.Webpart.Added.jpg)
8、点击工具栏上的Publish,页面即发布成功。
![164.Webpart.Complete.jpg](http://www.oceanstudio.net/oceanstudy/denny/Images/SharePoint/164.Webpart.Complete.jpg)
至此,编写一个最简单的WebPart的工作全部完毕。
当然,这个WebPart基本上没有任何作用,但通过学习编写该WebPart,我们就可以发现,WebPart也不是什么神秘的东西,它跟WebControl基本上一样的,只是使用方法有所不同。事实上,继承自System.Web.UI.WebControls.WebParts命名空间的WebPart,实际上就是WebControl,可以直接在Asp.NET 2.0中使用。
下一篇文章我将记录如何编写一个带事件的WebPart。欢迎大家继续关注:)多谢!