Wrap a User Control inside a Web Part using WSPBuilder
来源:互联网 发布:翟欣欣事件始末 知乎 编辑:程序博客网 时间:2024/06/05 02:19
First: Create User Control
Second: Create a WSPBuild Project, Then create web part feature.
protected override void CreateChildControls()
{
if (!_error)
{
try
{
base.CreateChildControls();
// Your code here...
//this.Controls.Add(new LiteralControl(this.MyProperty));
var uc = this.Page.LoadControl("/_controltemplates/ProductUT.ascx");
this.Controls.Add(uc);
}
catch (Exception ex)
{
HandleException(ex);
}
}
}
When I deployed this WSPProductUserCtrl.I run into the error following.
Error: Could not load the assembly. Make sure that it is compiled before accessing the page.
I searched through Internet. Then I found a solusion in under url.
(http://www.sharepointdev.net/sharepoint--development-programming/could-not-load-the-assembly-make-sure-that-it-is-compiled-before-accessing-the-page-error-while-45780.shtml).
Then I fixed this error.
Solusion: I copied the webapplication.dll and another dll which is used in User Control solusion into _appbin(C:/Inetpub/wwwroot/wss/VirtualDirectories/41305/_app_bin) folder. Then the error disappeared.
Steps for embeded usercontrol in webpart
When you embed a user control in a web part you have to add the dll from the user control to the /bin directory of your site's virtual directory...
1) Create User Control
2) Publish User Control
3) Add User Control to web part
3a) You want to add the User Control that is found in /Projects/<User Control Project Name>/PrecompiledWeb/<User Control Project Name>
4) Add reference of User Control to Web Part project
4a) this is found in /Projects/<User Control Project Name>/PrecompiledWeb/<User Control Project Name>/bin/Debug
4b) the file will be a random generated name...you can reference the name from the User Control in the "control" tag at the top of the .ascx file
5) Build Web Part Project
6) Add User Control dll that you can find either in location from Step 4a or from the /bin/Debug folder of the Web Part project
6a) The dll goes in the Virtual Directory /bin folder (Example: /inetpub/wwwroot/wss/VirtualDirectories/80/bin)
If you run into the following error,you should try to make some changes
Error:Could not load type 'MainNavigationUserCtl.MainNavUserCtl'
Solusion:
<%
@ Control Language="C#" AutoEventWireup="true" Inherits="MainNavigationUserCtl.MainNavUserCtl,MainNavigationUserCtl,Version=1.0.0.0, Culture=neutral, PublicKeyToken=6d819def51007e47" %>
- Wrap a User Control inside a Web Part using WSPBuilder
- Finding a Control Inside a Template
- Online CPU Console using a Web Control Library wit
- Selecting multiple checkboxes inside a GridView control
- Selecting multiple checkboxes inside a GridView control
- Custom Draw items inside a ListView Control
- Using a Context Menu on a Control
- LINQ to SQL系列Part 9-Using a Custom LINQ Expression with the control
- Part 6 - Generating a dropdownlist control in mvc using HTML helpers
- Part 9 - Generating a radiobuttonlist control in mvc using HTML helpers
- Create a ActiveX user control (VB.NET2005)
- Disable and enable a control using javascript
- 转:Creating a SharePoint Visual Web Part using Visual Studio 2010
- Updating a specific attribute inside an AutoCAD drawing using .NET
- Using TabLayout inside a Fragment; tab text invisible
- Formatting a Flex DataGrid control using a custom
- Using SVN as Source Control inside UE4
- A Programmer's Exploration of Vista's User Account Control
- Endnote X3 出现中文乱码
- Hibernate中createQuery与createSQLQuery两者的区别
- JAVA 程序实现国际化
- ESRI 安装过程中“The computer you chose is not a valid license server”
- 忙啊
- Wrap a User Control inside a Web Part using WSPBuilder
- 遍历双向链表
- 《Java开发有一说一》——Java读取Excel文件中的数据
- 摆脱恐惧、忧虑和自卑
- 一个多线程应用举例 : 优化界面交互
- ajax+json 做数据异步交互
- 选股方法之:量比和换手率(转载)
- @Override 的用法
- IL字节码分析