简体   繁体   English

如何重用ASP.NET .aspx或.ascx文件?

[英]How to re-use ASP.NET .aspx or .ascx files?

I know if someone wants to re-use some classes (not UI), he must gather all of them and put in a Visual Studio Class Library, build it to some dells and distribute these dlls. 我知道如果有人想重新使用某些类(而不是UI),他必须收集所有这些类并放入Visual Studio类库,将其构建到一些dell并分发这些dll。 In this approach there just one code, you just update code in one place. 在这种方法中只有一个代码,您只需在一个地方更新代码。

But what about ASP.NET's markups? 但是ASP.NET的标记呢? For example you have an .ascx file or a collection of .aspx files regarding user management. 例如,您有一个.ascx文件或一组关于用户管理的.aspx文件。 If I want to use them in another project I am forced to copy them in new project again. 如果我想在另一个项目中使用它们,我不得不再次在新项目中复制它们。 By this I have two same code that is very hard to maintain. 通过这个我有两个相同的代码,很难维护。

So is it any way to re-use .ascx and .aspx files just like simple .dlls? 那么重新使用.ascx和.aspx文件就像简单的.dll一样吗? For example building them? 比如建造它们?

Many Thanks, Afshar Mohebbi 非常感谢,Afshar Mohebbi

With the default configuration, .ascx and .aspx files will need to exist on disk, because they need to have a path associated with them for everything to work. 使用默认配置时, .ascx.aspx文件将需要存在于磁盘上,因为它们需要具有与之关联的路径才能使所有内容正常工作。 All the code (everything but the first line which specifies which class to inherit) in them, however, can be compiled away into a DLL file. 但是,所有代码(除了指定要继承哪个类的第一行之外的所有代码)都可以编译成DLL文件。 It would probably be possible to get around this by writing custom handlers and build providers that load things from DLLs, but it's not worth the effort. 通过编写自定义处理程序和构建从DLL加载东西的提供程序可能可以解决这个问题,但这不值得付出努力。

If you want to put your user controls into a DLL file, create them as custom controls instead of user controls (.ascx files). 如果要将用户控件放入DLL文件,请将它们创建为自定义控件而不是用户控件(.ascx文件)。 That's how all the custom control libraries for sale around the 'net are done. 这就是围绕'网络出售的所有自定义控制库的完成方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM