How to add user control on run time in ASP.NET?

后端 未结 4 1700
情话喂你
情话喂你 2021-01-18 23:55

How do I add a user control on page load dynamically in ASP.NET?

I have a div with ID=\"contentData\" and few controls

  • one.ascx
  • t
4条回答
  •  鱼传尺愫
    2021-01-19 00:47

    // Load the User Control
    
    Control uc = LoadControl("~/MyUserControl.ascx");
    
    // Add the User Control to the Controls collection
    
    Page.Controls.Add(uc);
    

    for more details go thru this link - An Extensive Examination of User Controls http://msdn.microsoft.com/en-us/library/ms972975.aspx

    Also do read the use of ~ tidle in .net http://msdn.microsoft.com/en-us/library/system.web.virtualpathutility.aspx

提交回复
热议问题