开发者

User Controls assembly in different projects?

Does anyone have an example on how to store user controls in an assembly for reuse across multiple projects?

I made an Assembly with my UserControls, but I had a lot of trouble when I tried to register the assemb开发者_JAVA技巧ly. Finally it worked but then when I tried to access an event I had the error "Object reference not set to an instance of an object",

Thanks very much.


User controls are not reusable across projects without a lot of pain. Namely, the .ascx files have to be available to each of the referencing projects, not just the assembly. This makes updates and deployments difficult. Possible, but very difficult depending on your environment.

Your best bet is to create a new assembly with Server Controls. The primary difference is that a server control is 100% code and easily transportable across projects. This means that you can't create composite controls by simply dragging and dropping them onto a design surface. However, you do have full control over the html emitted and can add the controls to a different project simply by referencing the assembly.

For a walkthrough on creating custom server controls see: http://msdn.microsoft.com/en-us/library/yhzc935f.aspx


The only other option other than what @Chris provided is you could find a utility (I know it exists because I know of people who used it) that merges the project containing the UC's into many child projects. Essentially it's code duplication, but you only then have to modify one code-base.


Take a look at this article:

http://weblogs.asp.net/scottgu/archive/2005/08/28/423888.aspx

It seems like it will require a lot of work to get it running, but it is possible. Another option is to convert the user controls into custom server controls, as explained here:

http://msdn.microsoft.com/en-us/library/aa479318.aspx


thanks very much guys for your answers and time. I think that I'm going to keep coping code in all my projects, cause this is getting too complicated, also I've found this article in MSDN http://msdn.microsoft.com/en-us/library/aa651710%28VS.71%29.aspx basically said that we have to make a separate copy in each application, Otherwise I have to use "Web custom controls" and my idea was to reuse those User controls and not to rewrite them. Now I have to look for my boss and kill him for give me this task and make me waste 3 days with this problem!! ;) Thanks very much Chris for editing my question, sometimes my english is terrible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜