Generic ServerControl syntax?

2019-06-28 00:21发布

Is there a way that I can have a server control

MyControl<T>

so that I can register and use it in an aspx page like so

<mc:MyControl<ThingForControlToUse> ID="instanceOfMyControl" runat="server"

Obviously the designer doesn't like this, are there any cool ways round it other than creating a non generic wrapper with a type parameter?

2条回答
男人必须洒脱
2楼-- · 2019-06-28 00:46

Generic Tag Names are not possible in ASP.NET, please refer to this article: Generic Controls

You are on the right track in thinking that you will need to create a wrapper with a TYPE parameter.

查看更多
贼婆χ
3楼-- · 2019-06-28 00:46

A quick note - I am not sure if this is true in Visual Studio 2008 but if you were to have that control in a project that you were editing with Visual Studio 2005 you would completely break intellisense with that control. When Visual Studio attempts to create XML schema files to use for intellisense popups in markup files it completely breaks when it sees generic controls like this one and it abandons the schema file completely leaving you with no intellisense for any controls in that assembly.

查看更多
登录 后发表回答