Hi @LA RC
I think the cause of the problem may be that you didn't increment the counter for the Panel. At the same time, we need to set a variable on the Page_PreInit page to make each Control's ID different. Take TextBox as an example (better display).
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs)
Dim keys As List(Of String) = Request.Form.AllKeys.Where(Function(key) key.Contains("txtDynamic")).ToList()
Dim i As Integer = 1
For Each key As String In keys
Me.Create("txtDynamic" & i)
i += 1
Next
End Sub
Protected Sub Add(ByVal sender As Object, ByVal e As EventArgs)
Dim index As Integer = Panel1.Controls.OfType(Of TextBox)().ToList().Count + 1
Me.Create("txtDynamic" & index)
End Sub
Private Sub Create(ByVal id As String)
Dim txt As TextBox = New TextBox()
txt.ID = id
Panel1.Controls.Add(txt)
Dim lt As Literal = New Literal()
lt.Text = "<br />"
Panel1.Controls.Add(lt)
End Sub
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
</Scripts>
</asp:ScriptManager>
<asp:Button ID="Button2" runat="server" Text="Prueba" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="jumbotron">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Add" />
<asp:TextBox ID="TextBox1" runat="server">20</asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server">0</asp:TextBox>
<asp:Panel ID="Panel1" runat="server" BorderStyle="Solid" HorizontalAlign="Left" ScrollBars="Both"></asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
As for how you want to change the style, just set it yourself.
Result:
Best regards,
Qi You
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.