将asp.net usercontrol,用户控件页转变为普通控件

步骤:

1. 建立一个WEB站点工程,创建一个ascx控件页,再创建一个aspx页面,将ascx放到aspx页面上,保证程序能正常运行;

2. 删除aspx文件, 点build->publish web site菜单, 在点出的窗口中: 取消选择:Allow this precompiled to be updatable,这样ascx页面的内容将会被编译到DLL中.

3. 选中Use fixed naming and single page assemblies, 这样只会生成一个DLL文件.

编译之后即可生成一个DLL.

然后新建一个WEB工程, 添加对这个DLL的引用, 在aspx页面顶端添加: <%@Register TagPrefix="mycontrol" Namespace="WebUserControl" Assembly="App_Web_helloworld.ascx.cdcab7d2"%>

具体的参数与创建ASCX工程和生成的DLL有关.

然后在页面中添加一行: <mycontrol:helloworld >http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/customcontrolfromusercontrol.asp