Create a usercontrol instance programmatically in ASP.NET

后端 未结 3 814
不知归路
不知归路 2021-01-07 04:58

I have a UserControl that I need to add dynamically. I tried to follow this MSDN article, but I\'m not having any success.... http://msdn.microsoft.com/en-us/library/c0az2h8

3条回答
  •  暖寄归人
    2021-01-07 05:47

    The ASP namespace is generated at run time- user controls get "compiled" as they are used by .aspx pages so this is why you get the error message "Type ASP.PictureGallery is not defined".

    When adding user controls dynamically you should use the Page.LoadControl method:

    Page.LoadControl("~/PictureGallery.ascx")
    

提交回复
热议问题