ASP.NET UserControl class library

前端 未结 6 1125
情话喂你
情话喂你 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:21

    Update: I was right on my hint on using the pre-compiled user control as you would an user control.

    For a step by step on how, see Turning an .ascx User Control into a Redistributable Custom Control

    There is no need for any .ascx files in the project where you'll use it, so this matches exactly what you were looking for.


    User Controls aren't meant to be reused across sites, use custom server controls instead.

    You can compose the server controls using existing controls, and set it up all so you can style through css.

    If you are still going for the user control approach, try what Bob mentioned in the answer. I haven't done it with user controls, but I would expect to be able to use the output of that approach like you would use a custom server control.

    <%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls"%>
    ...
    
    

    Ps. if that doesn't work, the link that he provided tells you to copy the ascx files anyway, so that wouldn't be what you were looking for i.e.try the above & if not stick to custom server controls.

提交回复
热议问题