Wrap a User Control inside a Web Part using WSPBuilder

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" %>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值