Hello Friends !,
How to access dynamically created textbox value or id to save into database.
Textbox is creating dynamically successfully. Now what I want suppose I fill the text and when I press button to save that value into database table. How do I get that textbox id.
Below what i tried to do please check and resolve this problem soon.
aspx-----------
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dynamic-TextBox.aspx.cs" Inherits="Dynamic_TextBox" %>
- >
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>title>
- head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:PlaceHolder ID="PlaceHolder1" runat="server">asp:PlaceHolder>
- <asp:Label ID="Label1" runat="server">asp:Label>
- <asp:Button ID="addnewtext" runat="server" Text="Add" onclick="addnewtext_Click" width="76px" />
- <asp:Button ID="btn_Save" runat="server" Text="Save Value" onclick="btn_Save_Click" />
- div>
- form>
- body>
- html>
.cs--------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Dynamic_TextBox : System.Web.UI.Page
- {
- static Random random = new Random();
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- TextBox tb;
- static int i = 0;
- protected void addnewtext_Click(object sender, EventArgs e)
- {
- i++;
- for (int j = 0; j <= i; j++)
- {
- GenerateRandomNumber();
- tb = new TextBox();
- tb.ID = j.ToString();
- PlaceHolder1.Controls.Add(tb);
- }
- }
- public void GenerateRandomNumber()
- {
- for (int i = 0; i < 2; i++)
- {
- Label1.Text = "The generated Random number is " + (Convert.ToString(random.Next(10, 200))); // to specify range for random number
- }
- }
- protected void btn_Save_Click(object sender, EventArgs e)
- {
- }
- }

Abhishek YadavPosted Oct 22, 2022, 1:55 AM
https://www.aspsnippets.com/Articles/Get-Value-Text-of-dynamically-created-TextBox-in-ASPNet-using-C-and-VBNet.aspx
Midhun TpPosted Nov 10, 2017, 4:27 AM
Manas MohapatraPosted Nov 9, 2017, 1:38 AM