guys i a m trying to build a webpage using c# as language in asp.net....
page consist of a button and i want is that when i click on that button a new textbox is added to the page dynamically on runtime..
My program works fine it adds a Textbox to the page ..but i want is that when i click again the button after clicking once i am able to add another text box but retaining the previous one...
but when i do that my previous one is lost
can any one please help me in this............
this is the code back file
Code:using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { public bool IsControlAdded { get { if (ViewState["IsControlAdded"] == null) ViewState["IsControlAdded"] = false; return (bool)ViewState["IsControlAdded"]; } set { ViewState["IsControlAdded"] = value; } } protected void Page_Load(object sender, EventArgs e) { if(IsControlAdded) AddUserControl(); } protected void btnLoad_Click(object sender, EventArgs e) { if (!IsControlAdded) AddUserControl(); } protected void btnSubmit_Click(object sender, EventArgs e) { } TextBox t; static int x=0; private void AddUserControl() { x =x+ 50; t = new TextBox(); t.ID = Convert.ToString(x); t.Style.Add("position", "Relative"); t.Style.Add("runat", "server"); t.Style.Add("left", "" + x + "px"); t.Style.Add("top", "" + x + "px"); Page.Form.Controls.Add(t); IsControlAdded = true; } }




Reply With Quote