Dynamic TextBox Disappear when Page get refreshed and How to store and Read Values in Dynamic TextBox.
Hello friends...
i am generationg Dynmic TextBox in asp.net
<asp:TextBox ID="txtNo" Width="50px" runat="server"></asp:TextBox>
<asp:Button ID="btnNo" runat="server" Text="How Many TextBox..?" OnClick="btnNo_Click" />
<p>
</p>
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="btnSearch" runat="server" Text="Search"
onclick="btnSearch_Click" />
</asp:Panel>
below is my code to generate dynamic textboxes:
public partial class WebForm1 : System.Web.UI.Page
{
TextBox txt1 = new TextBox();
protected void Page_Load(object sender, EventArgs e)
{
}
public void createBox()
{
Int16 intTotalNo;
intTotalNo = Convert.ToInt16(txtNo.Text);
for (int i = 1; i <= intTotalNo; i++)
{
TextBox box = new TextBox();
box.ID = "txt1" + i;
box.Width = Unit.Pixel(20);
box.MaxLength = 1;
box.EnableViewState = true;
PlaceHolder1.Controls.Add(box);
PlaceHolder1.Controls.Add(new LiteralControl(" "));
}
}
protected void btnNo_Click(object sender, EventArgs e)
{
createBox();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
}
now Above Code Generate TextBoxes. but when page get refreshed then all the Dynamic generated textBoxes may get disappeared...
so any one can help me how to resolve this problem and. how to store the value in dynamic generated textbox. and how to read that value from that TextBoxes...