Hi ramco11917,
Note:- For this sample i have refer below article. For more details refer below article link.
https://www.aspsnippets.com/Articles/Get-Value-Text-of-dynamically-created-TextBox-in-ASPNet-using-C-and-VBNet.aspx
Please refer below sample.
HTML
<asp:Button ID="btnAdd" runat="server" Text="+" OnClick="btnAdd_Click" />
<hr />
<asp:Panel ID="pnltxtBoxes" runat="server">
</asp:Panel>
Code
C#
protected void Page_PreInit(object sender, EventArgs e)
{
List<string> keys = Request.Form.AllKeys.Where(key => key.Contains("txtDynamic")).ToList();
int i = 1;
foreach (string key in keys)
{
this.CreateTextBox("txtDynamic" + i);
i++;
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
int index = pnltxtBoxes.Controls.OfType<TextBox>().ToList().Count + 1;
this.CreateTextBox("txtDynamic" + index);
}
private void CreateTextBox(string id)
{
TextBox txt = new TextBox();
txt.ID = id;
pnltxtBoxes.Controls.Add(txt);
Literal lt = new Literal();
lt.Text = "<br />";
pnltxtBoxes.Controls.Add(lt);
}
VB.Net
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Init
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.CreateTextBox("txtDynamic" & i)
i += 1
Next
End Sub
Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim index As Integer = pnltxtBoxes.Controls.OfType(Of TextBox)().ToList().Count + 1
Me.CreateTextBox("txtDynamic" & index)
End Sub
Private Sub CreateTextBox(ByVal id As String)
Dim txt As TextBox = New TextBox()
txt.ID = id
pnltxtBoxes.Controls.Add(txt)
Dim lt As Literal = New Literal()
lt.Text = "<br />"
pnltxtBoxes.Controls.Add(lt)
End Sub
Screenshot