How to Access Dynamicaly created controls
-
Hi all, i m asking in case of ASP.Net... where in the page i m dynamically creating Table & inside tables i m adding text box & drop down combo as literal controls... and then i add the Table to page's controls collection Now i call the function which creates the dynamic table .. in Page Load it works fine for 1st time... but during Post Back its not creatig the page again nor i can change/set the value inside the text box dynamically. how can i access the values inside the Text Boxes the code is something like this namespace Motel { public class WebForm5 : System.Web.UI.Page { //Variables declarations here.... private void Page_Load(object sender, System.EventArgs e) { if(this.IsPostBack == true) { tot1 = (int.Parse(Request["dpersonsid"])); tot0 = (int.Parse(Request["dpid"])); if(tot1 <= 1) { tot2=int.Parse(Request["rent1"].ToString()) ; } else { tot2=int.Parse(Request["rent2"].ToString()) ; } int tot3 = (tot0)*(tot2); this.total.Text = tot3.ToString(); TextBox1.Text = tot3.ToString(); } else { //if not post back setPage(); } void setPage() { while(areader.Read()) { tb=new Table(); TableRow tr=new TableRow(); TableCell tcell=new TableCell(); tcell.Controls.Add(new LiteralControl("Room Type "+areader["RoomType"].ToString())); tr.Cells.Add(tcell); tb.Rows.Add(tr); myPlaceHolder.Controls.Add(tb); dpRooms = new DropDownList(); dpRooms.AutoPostBack =true; dpRooms.ID = "dpid"; dpRooms.Items.Add(i.ToString()); tcell=new TableCell(); tcell.Controls.Add(dpRooms); tr.Cells.Add(tcell); dpersons = new DropDownList(); dpersons.AutoPostBack = true; dpersons.ID = "dpersonsid"; dpersons.Items.Add("1");dpersons.Items.Add("2"); dpersons.Width = 70; tcell=new TableCell(); tcell.Controls.Add((dpersons)) ; tr.Cells.Add(tcell); total = new TextBox() ; total.ID = "totalid"; total.Enabled = true; total.AutoPostBack =true; tcell=new TableCell(); tcell.Controls.Add((total)) ; tr.Cells.Add(tcell); } tb.Rows.Add(tr); myPlaceHolder.Controls.Add(tb); Page.EnableViewState = true; return; Plz Reply ASAP. Tahnx a lot :-O This is naresh
-
Hi all, i m asking in case of ASP.Net... where in the page i m dynamically creating Table & inside tables i m adding text box & drop down combo as literal controls... and then i add the Table to page's controls collection Now i call the function which creates the dynamic table .. in Page Load it works fine for 1st time... but during Post Back its not creatig the page again nor i can change/set the value inside the text box dynamically. how can i access the values inside the Text Boxes the code is something like this namespace Motel { public class WebForm5 : System.Web.UI.Page { //Variables declarations here.... private void Page_Load(object sender, System.EventArgs e) { if(this.IsPostBack == true) { tot1 = (int.Parse(Request["dpersonsid"])); tot0 = (int.Parse(Request["dpid"])); if(tot1 <= 1) { tot2=int.Parse(Request["rent1"].ToString()) ; } else { tot2=int.Parse(Request["rent2"].ToString()) ; } int tot3 = (tot0)*(tot2); this.total.Text = tot3.ToString(); TextBox1.Text = tot3.ToString(); } else { //if not post back setPage(); } void setPage() { while(areader.Read()) { tb=new Table(); TableRow tr=new TableRow(); TableCell tcell=new TableCell(); tcell.Controls.Add(new LiteralControl("Room Type "+areader["RoomType"].ToString())); tr.Cells.Add(tcell); tb.Rows.Add(tr); myPlaceHolder.Controls.Add(tb); dpRooms = new DropDownList(); dpRooms.AutoPostBack =true; dpRooms.ID = "dpid"; dpRooms.Items.Add(i.ToString()); tcell=new TableCell(); tcell.Controls.Add(dpRooms); tr.Cells.Add(tcell); dpersons = new DropDownList(); dpersons.AutoPostBack = true; dpersons.ID = "dpersonsid"; dpersons.Items.Add("1");dpersons.Items.Add("2"); dpersons.Width = 70; tcell=new TableCell(); tcell.Controls.Add((dpersons)) ; tr.Cells.Add(tcell); total = new TextBox() ; total.ID = "totalid"; total.Enabled = true; total.AutoPostBack =true; tcell=new TableCell(); tcell.Controls.Add((total)) ; tr.Cells.Add(tcell); } tb.Rows.Add(tr); myPlaceHolder.Controls.Add(tb); Page.EnableViewState = true; return; Plz Reply ASAP. Tahnx a lot :-O This is naresh