Note that there are some explanatory texts on larger screens.

plurals
  1. POTextbox disappears when linkbutton is clicked
    primarykey
    data
    text
    <p>I have a problem. I'm trying to make some panels, and in these panels I would like to have some linkbuttons, when the user click a linkbutton of a panel a textbox will appear in that panel, when I click in another linkbutton the textboxes of that panel also appear without problem but when I click in the other linkbutton the texboxes created in the previous panel disappears. </p> <p>Here is my code:</p> <pre><code>public partial class _Default : Page { Label myLabel1; Label myLabel2; protected void Page_Load(object sender, EventArgs e) { myLabel1 = new Label(); myLabel2 = new Label(); Panel1.Controls.Add(myLabel1); Panel2.Controls.Add(myLabel2); if (!Page.IsPostBack) { //Remove the session when first time page loads. Session.Remove("clicks"); Session.Remove("clicks2"); } } protected void LinkButton1_Click(object sender, EventArgs e) { int rowCount = 0; //initialize a session. rowCount = Convert.ToInt32(Session["clicks"]); rowCount++; //In each button clic save the numbers into the session. Session["clicks"] = rowCount; //Create the textboxes and labels each time the button is clicked. for (int i = 0; i &lt; rowCount; i++) { TextBox TxtBoxU = new TextBox(); TxtBoxU.ID = "TextBoxU" + i.ToString(); //Add the labels and textboxes to the Panel. Panel1.Controls.Add(TxtBoxU); } myLabel1.Text = rowCount + ""; } protected void LinkButton2_Click(object sender, EventArgs e) { int rowCount2 = 0; //initialize a session. rowCount2 = Convert.ToInt32(Session["clicks2"]); rowCount2++; //In each button clic save the numbers into the session. Session["clicks2"] = rowCount2; //Create the textboxes and labels each time the button is clicked. for (int i = 0; i &lt; rowCount2; i++) { TextBox TxtBoxU = new TextBox(); TxtBoxU.ID = "TextBoxU" + i.ToString(); //Add the labels and textboxes to the Panel. Panel2.Controls.Add(TxtBoxU); } myLabel2.Text = rowCount2 + ""; } } </code></pre> <p>And here is the other part:</p> <pre><code>&lt;form id="form1" runat="server"&gt; &lt;p&gt; Part I&lt;/p&gt; &lt;asp:Panel ID="Panel1" runat="server" Height="53px"&gt; &lt;asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"&gt;Add to 1&lt;/asp:LinkButton&gt; &lt;br /&gt; &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;/asp:Panel&gt; &lt;asp:Panel ID="Panel2" runat="server" Height="51px"&gt; &lt;asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click"&gt;Add to 2&lt;/asp:LinkButton&gt; &lt;br /&gt; &lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;/asp:Panel&gt; &lt;/form&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