ASP.NET- Instantiate a Web User Control in App_Code class

后端 未结 2 1430
北海茫月
北海茫月 2021-01-19 14:12

Files:

Website\\Controls\\map.ascx

Website\\App_Code\\map.cs

I\'d like to create a strongly typed instance of map.ascx in map.cs

Normally, in

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 14:31

    Normally, I'd do something like this (assuming your type is "Map" and that you have the appropriate "Inherits" declaration in your .ascx file):

    Map map = (Map)LoadControl("~/Controls/map.ascx");
    

提交回复
热议问题