最近在项目开发过程中,经常会写Web Part,但是Web Part开发调试不是那么方便,我就想能不能先用User Control开发自己的模块,然后把User Control加到Web Part里面去呢? 这样不仅能够提高开发效率,而且也能复用以前开发过的模块。下面就详细说明具体如何操作:
  1. 新建一个Class library project,添加对System.Web的引用
  在Web Part中使用User Control
 
2. 项目添加一个user control
  在Web Part中使用User Control
 
3. 编写这个Web Part
 在Web Part中使用User Control
  4. 为程序集添加强名称
在Web Part中使用User Control
 
  5. 更改build的输出目录,改为C:\Inetpub\wwwroot\wss\VirtualDirectories\[Site的端口号]\_app_bin\
在Web Part中使用User Control
  6. 修改AssemblyInfo.cs,添加using System.Security;和 [assembly: AllowPartiallyTrustedCallers()]
  在Web Part中使用User Control
 
  7. 更改user control的属性,将Copy to output directory改为copy if newer
  在Web Part中使用User Control
 
  8. Build工程

  9. 用Reflector打开刚刚生成的dll,找到Assembly的信息
  在Web Part中使用User Control
 
  10. 打开C:\Inetpub\wwwroot\wss\VirtualDirectories\[Site 端口号]\web.config文件,在SafeControls下添加一行
     <SafeControl Assembly="BR.WebParts.UControlDemo1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1e038d98fe593539" Namespace="BR.WebParts.UControlDemo1"  TypeName="UserControlPart" Safe="True"/>
  其中Assembly的信息是从Reflector里面取到的
 10.最后把这个Web Part添加到网页上就可以了

KaneBoy的一篇文章提到使用Feature的部署DelegateContorl的方式部署一个ascx文件到站点集的Feature

转载于:https://www.cnblogs.com/blusehuang/archive/2007/06/26/796546.html

相关文章:

  • 2021-10-02
  • 2021-12-24
  • 2022-12-23
  • 2021-08-09
  • 2021-06-22
  • 2022-12-23
  • 2021-09-22
猜你喜欢
  • 2021-10-05
  • 2021-10-16
  • 2021-09-22
  • 2021-04-21
  • 2021-10-18
  • 2021-12-05
相关资源
相似解决方案