ASP.NET UserControl class library

前端 未结 6 1124
情话喂你
情话喂你 2021-02-08 12:11

Is it possible to create class libraries that contain UserControls so I can reuse them? If so, how? Is the markup compiled with the .dll? Thanks for any help!

6条回答
  •  终归单人心
    2021-02-08 12:37

    If we are talking about web-forms, The answer is no. The markup (.ascx file contents) is not compiled into the dll. The ASP.NET engine expects to find this file in the file system, along with the web application. So it is not possible to create a DLL that you can simply redistribute or share.

    If you want to create controls that can be shared across web-applications, you can create custom controls instead, but then you have to code up the HTML in .net code (preferebly using the appropriate classes for the task instead of just creating html in text), which can get pretty ugly if the control is big.

    Personally, I think it is pretty annoying that it is this way.

    I think however, that if you are using ASP.NET MVC, there are some possibilities (depending on your view engine), but I don't have much experience with MVC.

提交回复
热议问题