Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding dynamically added server control and use it's HTML
    primarykey
    data
    text
    <p>I'm trying to get Text from a dynamically craeted server textbox. I'm just checking by getting the text into another textbox I placed in the aspx file, but all I get is always an empty string.. (I also tried another method that is enclosed in remark, but it doesn't work either)</p> <p>Here's the code behind:</p> <pre><code>public partial class Product_list : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { create_table(); } protected void create_table() { DBServices db1=new DBServices(); List&lt;Product&gt; list1 = db1.ReadProducts(); int id_number=1; int id_numer2 = 7; int id_number3 = 13; Table tbl = new Table(); tbl.ID = "tbl1"; this.Controls.Add(tbl); foreach (Product p1 in list1) { TableRow rw = new TableRow(); rw.ID = Convert.ToString(id_numer2); TableCell cell1 = new TableCell(); cell1.Text = p1.Name; TableCell cell2 = new TableCell(); Image img = new Image(); img.ImageUrl = p1.ImagePath; img.Height = 50; img.Width = 50; cell2.Controls.Add(img); TableCell cell3 = new TableCell(); cell3.ID = Convert.ToString(id_number3); TextBox textbox1 = new TextBox(); textbox1.ID = Convert.ToString(id_number); cell3.Controls.Add(textbox1); rw.Controls.Add(cell1); rw.Controls.Add(cell2); rw.Controls.Add(cell3); tbl.Controls.Add(rw); id_number++; id_numer2++; id_number3++; } } void save_list() { List&lt;Product&gt; Items_list = new List&lt;Product&gt;(); //TextBox aControl =Page.FindControl("1") as TextBox; /var tbl1 = this.Page.FindControl("tbl1") as Table; var tr = tbl1.FindControl("7") as TableRow; var td = tr.FindControl("13") as TableCell; var txt = td.FindControl("1") as TextBox; txt1.Value = txt.Text; } protected void Button1_Click(object sender, EventArgs e) { save_list(); } } </code></pre> <p>and here is the aspx code:</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Product_list.aspx.cs" Inherits="Product_list" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script runat=server&gt; public override void VerifyRenderingInServerForm(Control control) { } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div id="header"&gt; &lt;h1&gt;Items List&lt;/h1&gt; &lt;/div&gt; &lt;div id="prod_table" runat="server"&gt;&lt;/div&gt; &lt;div&gt; &lt;input type="text" runat="server" id="txt1" /&gt; &lt;asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload