ASP.NET: ¿Cómo creo un widget / control de usuario que pueda usarse con otras soluciones?

I am looking to create a widget that can be used with other solutions. The widget is a competition widget that can be placed in different parts of the site. What is the best way to do this? Should I create a new solution to hold this in?

preguntado el 08 de noviembre de 11 a las 09:11

5 Respuestas

Create a new class library project (you can have it within your current solution if it suits) and create your server controls in there. You can then reference this library from whatever websites you need.

respondido 08 nov., 11:13

You need to create a Web Control, not a User Control, if you want o use it in other projects. This question details the different control types, you may find it useful: ¿Cuál es la diferencia entre UserControl, WebControl, RenderedControl y CompositeControl?

contestado el 23 de mayo de 17 a las 13:05

Here is relatively simple tutorial on creating a custom WebControl:
Create ASP.NET Server Controls from Scratch

And here some more advanced example from MSDN:
Desarrollo de controles de servidor ASP.NET personalizados

respondido 08 nov., 11:13

It depends if you will be using it in other solutions really. If you are, then if might make more sense to create a new widgets solution with each widget in its own user control and compile it into an assembly.

Then you just reference that assembly and use it in your markup.

If your widget is only going to be used in a single solution then I wouldn't bother with the above. Just create a user control in the same solution.

respondido 08 nov., 11:13

As opposite of some answers, you should create user controls with embedded resources.

It is complex to do it, but once you do you will be able to develop controls like RadControls from Telerik.

If you open up their controls you will see that they are all embedded resources al Telerik.Web.UI.dll.

Here is an old answer of mine that shows how to load the control and how to handle embedded resources (virtual path provider)

Unless you have a good reason to do so (like creating a generic control as a calendar, grid or something like that) don't go this way, it is dark, complex... But as you can see it might be worth it, Telerik.Web.UI is the live example that this can work out.

contestado el 23 de mayo de 17 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.