Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to separate different textboxes in a control?
    primarykey
    data
    text
    <p>I have three <code>Textboxes</code> that I don't know how to separate from each others to get the correct value. I Create the <code>Textboxes</code> in <code>GetTrix();</code> and when I try to update the <strong>value</strong> the <strong>values</strong> are wrong because there's no difference between them.</p> <pre><code> protected void btnUpdate_Click(object sender, EventArgs e) { string TrixName = null; string TrixID = null; string Hardness = null; string Webpage = null; foreach (Control c in phdTrix.Controls) { if (c.GetType() == typeof(TextBox)) { //This is where there is no difference between the textboxes TrixName = (c as TextBox).Text; TrixID = (c as TextBox).ID; Hardness = (c as TextBox).Text; Webpage = (c as TextBox).Text; UpdateTrix(TrixID, TrixName, Hardness, Webpage); } } } private void GetTrix() { DataTable table = CategoryAccess.GetAllTrix(); for (int i = 0; i &lt; table.Rows.Count; i++) { TextBox textbox = new TextBox(); textbox.ID = table.Rows[i]["TrixID"].ToString(); textbox.Text = table.Rows[i]["TrixName"].ToString(); Literal literal1 = new Literal(); literal1.Text = "&lt;p&gt;"; TextBox textbox2 = new TextBox(); textbox2.Text = table.Rows[i]["Hardness"].ToString(); TextBox textbox3 = new TextBox(); textbox3.Text = table.Rows[i]["Webpage"].ToString(); Literal literal2 = new Literal(); literal2.Text = "&lt;/p&gt;"; phdTrix.Controls.Add(literal1); phdTrix.Controls.Add(textbox); phdTrix.Controls.Add(textbox2); phdTrix.Controls.Add(textbox3); phdTrix.Controls.Add(literal2); } } </code></pre> <p>This would be a logic solution. But dosent work.</p> <pre><code>TrixName = (c as TextBox textbox).Text; Hardness = (c as TextBox textbox2).Text; Webpage = (c as TextBox textbox3).Text; </code></pre> <p>The new code:</p> <pre><code> protected void btnUpdate_Click(object sender, EventArgs e) { string TrixID = null; string TrixName = null; string Hardness = null; string Webpage = null; foreach (Control c in phdTrix.Controls) { if (c.GetType() == typeof(TextBox)) { TrixID = (c as Literal).Text; switch (c.ID) { case "TrixName": TrixName = (c as TextBox).Text; break; case "Hardness": Hardness = (c as TextBox).Text; break; case "Webpage": Webpage = (c as TextBox).Text; break; } UpdateTrix(TrixID, TrixName, Hardness, Webpage); } } } private void GetTrix() { DataTable table = CategoryAccess.GetAllTrix(); for (int i = 0; i &lt; table.Rows.Count; i++) { Literal literalTrixID = new Literal(); literalTrixID.Text = table.Rows[i]["TrixID"].ToString(); literalTrixID.Visible = false; TextBox textbox = new TextBox(); textbox.ID = "TrixName"; textbox.Text = table.Rows[i]["TrixName"].ToString(); Literal literal1 = new Literal(); literal1.Text = "&lt;p&gt;"; TextBox textbox2 = new TextBox(); textbox2.ID = "Hardness"; textbox2.Text = table.Rows[i]["Hardness"].ToString(); TextBox textbox3 = new TextBox(); textbox3.ID = "Webpage"; textbox3.Text = table.Rows[i]["Webpage"].ToString(); Literal literal2 = new Literal(); literal2.Text = "&lt;/p&gt;"; phdTrix.Controls.Add(literalTrixID); phdTrix.Controls.Add(literal1); phdTrix.Controls.Add(textbox); phdTrix.Controls.Add(textbox2); phdTrix.Controls.Add(textbox3); phdTrix.Controls.Add(literal2); } } </code></pre> <p>I get an error: Several control's with the same ID (<code>TrixName</code>) were found. <code>FindControl</code> have to have a Unique ID.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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