简体   繁体   中英

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. In this approach there just one code, you just update code in one place.

But what about ASP.NET's markups? For example you have an .ascx file or a collection of .aspx files regarding user management. 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? For example building them?

Many Thanks, 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. 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. 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.

If you want to put your user controls into a DLL file, create them as custom controls instead of user controls (.ascx files). That's how all the custom control libraries for sale around the 'net are done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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