How to add controls dynamically to ASP.NET form?

后端 未结 6 1790
说谎
说谎 2021-01-12 02:16

I do not know how to add controls dynamically to the form using C# .net. Can anyone help me? I know this with vb.net but I need to know the syntax in C#.

6条回答
  •  Happy的楠姐
    2021-01-12 02:30

    In Aspx

    <%@ Reference Control = "WebUserControl1.ascx" %>
    

    U can use the following in the Cs file to laod the control dynamically...

    if (case)
    else
    {
    WebUserControl1 uc = 
          (WebUserControl1) Page.LoadControl("WebUserControl1.ascx"); 
        PlaceHolder1.Controls.Add(uc); 
    
    
    }
    

    or try this

     Content.Controls.Add(Page.LoadControl("UserControls/InventoryNav.ascx"));
    

    Can also have a look at:

    http://aspalliance.com/565

    http://samuelmueller.com/2008/12/dynamicloader-plugin-dynamically-loading-asp-net-user-controls-with-jquery

    http://forums.asp.net/p/1222567/2826338.aspx

提交回复
热议问题