概述
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的全部内容,希望文章能够帮你解决Wrap a User Control inside a Web Part using WSPBuilder所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复