How to reuse ASP.NET.aspx or .ascx files?

I know that if someone wants to reuse some classes (and not the user interface), he must collect all of them and put them in the Visual Studio class library, build it in some domains and distribute these DLLs. There is only one code in this approach, you just update the code in one place.

But what about ASP.NET markup? For example, you have a .ascx file or a collection of .aspx files related to user management. If I want to use them in another project, I have to copy them again to a new project. However, I have two identical codes that are very difficult to maintain.

So is it possible to reuse .ascx and .aspx files in the same way as simple DLLs? For example, building them?

Thanks a lot, Afshar Mohebby

+4
source share
1 answer

In the default configuration, the .ascx and .aspx files must exist on the disk, because for them to work, you must have a path associated with them. However, all code (everything except the first line, which indicates which class inherits) in them can be compiled into a DLL file. You can probably get around this by writing custom handlers and creating vendors that load things from the DLL, but it's not worth the effort.

If you want to put your user controls in a DLL file, create them as custom controls instead of user controls (.ascx files). This is the way all user control libraries for sale around the "network" are made.

+6
source

Source: https://habr.com/ru/post/1311414/


All Articles