How to add a new panel at runtime in asp.net

I am working on an asp.net web application where I have a predefined panel in my project. CSS Now I want to create another panel with the same design and CSS at runtime several times. I have a control button, when I click on this button, it will add another panel.

Please help me add another panel with the same criteria.

+3
source share
3 answers

If this is what you plan to reuse, I would suggest you use a custom control for this. You can simply add a new instance of the control on your page.

, :

, ...

//MyControl = Custom User Control
var myControl =  (MyControl) Page.LoadControl("MyControl.ascx"); 
this.ControlContainer.Controls.Add(myControl);
+4

RSolberg, User Control :

<my:UserControl id="MyControl1" runat="server" />
<my:UserControl id="MyControl2" runat="server" />
<my:UserControl id="MyControl3" runat="server" />

, User Control , , .

, , - ASP.NET Repeater, ListView DataGrid. - /, . Repeater HTML/CSS , , .

<asp:Repeater id="MyRepeater" runat="server">
  <HeaderTemplate>
    <h1>Products</h1>
  </HeaderTemplate>
  <ItemTemplate>
    <p>
      Product name: <%# Eval("ProductName") %>
    </p>
  </ItemTemplate>
</asp:Repeater>

:

MyRepeater.DataSource = products;
MyRepeater.DataBind();

ASP.NET , , - , .

+1

"On_Click"? . , , -, .

-1
source

Source: https://habr.com/ru/post/1716357/


All Articles