I am using ASP.NET/C#
.
In one of my page I am using Update Panel
.Inside my Update Panel
I have a LinkButton
which adds Textbox
inside the Update Panel
.
The Textboxes
are created dynamically and it is working fine.However when I click
the same Linkbutton
to add next Textbox
, the value of my previous Textbox
is lost.
I think this is because of PostBack
.
Here is my code for creating Textboxes
.
protected void linkAddAmount_Click(object sender, EventArgs e)
{
int count = 0;
if (ViewState["ButtonCount"] != null)
{
count = (int)ViewState["ButtonCount"];
}
count++;
ViewState["ButtonCount"] = count;
for (int i = 0; i < count; i++)
{
AmountUpdatePanel.ContentTemplateContainer.Controls.Add(new LiteralControl("<span>From: </span>"));
TextBox textbox1 = new TextBox();
textbox1.ID = "txtAmountFrom" + i;
textbox1.Attributes.Add("class", "ShortTextbox");
AmountUpdatePanel.ContentTemplateContainer.Controls.Add(textbox1);
}
}
Can anyone help me to solve this issue?
Any suggestion is welcome.