Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Controls and Generics

can ASP.NET controls be used with generics? Never seen this done and want a way to differentiate some controls on a page by type, ie: DateTime vs int

example:

public class MyGenericTextBox<T>: TextBox
{
public MyGenericTextBox<T>() {... }
}
like image 724
mirezus Avatar asked Nov 16 '25 13:11

mirezus


2 Answers

It can be done with a special hack, for example the one I used in this article:

A Typed Repeater in ASP.NET

However I would not recommend doing this just for convenience in simple cases, since the result would be more complex than the thing you'll try to improve.

like image 121
Andrey Shchekin Avatar answered Nov 19 '25 08:11

Andrey Shchekin


Be careful - Visual Studio cannot create intellisense schemas when one of the classes in an assembly of controls is generic. Someone added a control like this to one of our projects and it took us two months to figure out why we had no intellisense in our markup.

like image 45
Andrew Hare Avatar answered Nov 19 '25 09:11

Andrew Hare