Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to delete dynamic created textbox controls on dropdownlist selectedIndexChanged event and recreate new dynamic control on new selected value
    primarykey
    data
    text
    <pre><code> Aspx page: &lt;table border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:placeholder id="container" runat="server" visible="false"&gt;&lt;/asp:placeholder&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; On Code Behind file: protected override void OnLoad(EventArgs e) { base.OnLoad(e); generateDynamicControls(); } private void generateDynamicControls() { for (int i = 0; i &lt; dt.Rows.Count; i++) { HtmlGenericControl tr = new HtmlGenericControl("tr"); HtmlGenericControl td1 = new HtmlGenericControl("td"); Label lbl = new Label(); lbl.ID = "lbl" + dt.Rows[i]["sSubjectName"].ToString(); lbl.Text = dt.Rows[i]["sSubjectName"].ToString() + " :"; lbl.Width = new Unit(170); lbl.Style.Add("padding-left", "10px"); lbl.Style.Add("font-weight", "bold"); td1.Controls.Add(lbl); tr.Controls.Add(td1); HtmlGenericControl td2 = new HtmlGenericControl("td"); TextBox txtBox = new TextBox(); txtBox.ID = "txt" + dt.Rows[i]["sSubjectName"].ToString(); txtBox.CssClass = "TxtBox"; txtBox.TextMode = TextBoxMode.MultiLine; txtBox.Width = new Unit(840); td2.Style.Add("colspan", "3"); td2.Controls.Add(txtBox); tr.Controls.Add(td2); container.Controls.Add(tr); HtmlGenericControl tr1 = new HtmlGenericControl("tr"); HtmlGenericControl td3 = new HtmlGenericControl("td"); td3.Style.Add("colspan", "4"); td3.InnerHtml = "&amp;nbsp;"; tr1.Controls.Add(td3); container.Controls.Add(tr1); //container.Controls.Add(new LiteralControl("&lt;br /&gt;")); //LiteralControl literalBreak = new LiteralControl(); //literalBreak.Text ="&lt;/br&gt;"; } container.Visible = true; } } `dt(datatable)` is filled from other function. </code></pre> <p>this is working fine and controls are created correclty.</p> <p>But I want to recreate this dynamic controls on selected change event of dropdownlist. but before recreate these controls i have to delete previously created controls. </p> <p>I have tried below code in dropdownlist selected changed event to delete these controls and recreate new controls.</p> <pre><code>for (int i = 0; i &lt; dt.Rows.Count; i++) { container.Controls.Remove(container.FindControl(dt.Rows[i]["nSubjectId"].ToString())); } generateDynamicControls(); </code></pre> <p>But it's not work and give me following error. becuase of onload event is alread ycalled first and created the dyanmic controls.</p> <p>Multiple controls with the same ID '<em>lblOrals</em>' were found. FindControl requires that controls have unique IDs.</p> <p>How can I solve this problem.</p> <p>Please help me solve this problem.</p> <p>Thanks in advance</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