从其他项目使用用户控件 [英] Using a User Control from Another Project

查看:138
本文介绍了从其他项目使用用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立的,我想重新使用一个单独的项目一期工程中的用户控件。我看到了类似的尝试,加入一个参照原始项目,然后通过注册的控制成功地完成了:

I have built a user control in a project that I want to re-use in a separate project. I had seen similar attempts successfully accomplished by adding a reference to the original project and then registering the control via:

<%@ Register Assembly="AssemblyName" Namespace="AssemblyName.Namespace" TagPrefix="xxx" %>

我做了一件类似的,编译原来的项目,并在以后一个的引用它。控制器有一个asp:在它Repeater控件。然后我注册了我的控制,上面并放置在控制我的网页上像这样(的控制有一个字符串属性命名的道具):

I did something similar, compiling the original project and referencing it in the subsequent one . The control has an asp:Repeater control within it. I then registered my control as above and placed the control on my page like so (the control has a string property named prop):

<xxx:ControlName ID="ControlId" runat="server" prop="21" />

然而,当我启动了后续项目的控制,我得到一个空引用异常,应用程序扼流圈。难道我这做了错误的方式?它是强制性的,我在以后的项目中的.ascx文件?

However when I launch the control in the subsequent project, I get a null reference exception and the application chokes. Am I doing this the wrong way? Is it mandatory that I have an .ascx file in the subsequent project?

任何及所有的帮助是AP preciated。

Any and all help is appreciated.

谢谢

PBR

推荐答案

正如跟进这样的:

我做了一些进一步的研究,得知标记语言(中的.ascx网站上的资料)不会被编译成汇编。因此,你的必须的有一个调用它,如果没有与控制有关的任何标记的项目中的.ascx文件。

I did some further research and learned that the mark-up language (materials on the .ascx page) do not get compiled into the assembly. Therefore you must have the .ascx file within the project that calls it if there is any markup associated with the control.

在属性对话框我设置了一个生成后事件副本.ascx文件转移到后续的项目控制文件。我引用它,因为我将任何普通用户控制,一切工作正常。

In the properties dialogue I set up a post-build event that copies the .ascx file over to the subsequent project Controls file. I reference it as I would any normal User Control and everything works fine.

希望这有助于有人用类似的问题在那里,

Hope this helps someone out there with a similar issue,

PBR

这篇关于从其他项目使用用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆