Adding CheckBox control at runtime
-
How to add a checkbox control at runtime in a Panel using placeholder or wihtout using ph. I have added the control, but controls are added on the same location i think. So its showing a single control. Is it possible to do it in the Javascript function.so that there will be no page rendering. Wherein in a windows application we can specify the location.Im using ASP.Net 2.0 and C# as code behind. Plese help me to solve this problem. Thanks in advance. Its a urgent requirement. Help me out. Regards Mukil.
-
How to add a checkbox control at runtime in a Panel using placeholder or wihtout using ph. I have added the control, but controls are added on the same location i think. So its showing a single control. Is it possible to do it in the Javascript function.so that there will be no page rendering. Wherein in a windows application we can specify the location.Im using ASP.Net 2.0 and C# as code behind. Plese help me to solve this problem. Thanks in advance. Its a urgent requirement. Help me out. Regards Mukil.
You must put it at end of PageLoad... Because ViewState will refreshed after PageLoad event CheckBox chb = new CheckBox(); chb.ID = "someID"; pnl.Controls.Add(chb); pnl - is your Panel which you added in designer... It is simple or I didn't understand what is a problem in?..
-
You must put it at end of PageLoad... Because ViewState will refreshed after PageLoad event CheckBox chb = new CheckBox(); chb.ID = "someID"; pnl.Controls.Add(chb); pnl - is your Panel which you added in designer... It is simple or I didn't understand what is a problem in?..
Instead of the Page Load, sometimes I have had to add the Controls at runtime before the OnInit() Method ends. As Russel has said, if not, you will lose the ViewState and you won't be able to recover the value of the CheckBox. Remember to do a FindControl ( "CheckBoxID" ) in the PlaceHolder to get the CheckBox Ricardo Casquete
-
Instead of the Page Load, sometimes I have had to add the Controls at runtime before the OnInit() Method ends. As Russel has said, if not, you will lose the ViewState and you won't be able to recover the value of the CheckBox. Remember to do a FindControl ( "CheckBoxID" ) in the PlaceHolder to get the CheckBox Ricardo Casquete
My problem is, In button click i need to add button as many as i want. But Once the control is adding, because as you said postback and page rendering. How to avoid this. Please help me out. The code is given below, I have tried with html table and adding rows and cells within rows. TextBox txtName = new TextBox(); txtName.ID = "txtName"; txtName.Visible = true; txtName.Width = 150; txtName.Text = "Check"; PHItem.Controls.Add(txtName); Using Table: HtmlTableRow htrow = new HtmlTableRow(); HtmlTableCell htcell = new HtmlTableCell(); TextBox txtName = new TextBox(); txtName.ID = "txtName"; txtName.Visible = true; txtName.Width = 150; txtName.Text = "Check"; htcell.Controls.Add(txtName); htrow.Cells.Add(htcell);
-
My problem is, In button click i need to add button as many as i want. But Once the control is adding, because as you said postback and page rendering. How to avoid this. Please help me out. The code is given below, I have tried with html table and adding rows and cells within rows. TextBox txtName = new TextBox(); txtName.ID = "txtName"; txtName.Visible = true; txtName.Width = 150; txtName.Text = "Check"; PHItem.Controls.Add(txtName); Using Table: HtmlTableRow htrow = new HtmlTableRow(); HtmlTableCell htcell = new HtmlTableCell(); TextBox txtName = new TextBox(); txtName.ID = "txtName"; txtName.Visible = true; txtName.Width = 150; txtName.Text = "Check"; htcell.Controls.Add(txtName); htrow.Cells.Add(htcell);
I would create a class used to capture the rows or buttons. Just create arrays or properties with the class mark it as [Serializable] and save it to the view at the end of page load or when ever you add them Then on post back on the PageLoad event recreate the tables or buttons based on what you saved in the view state. 1 line of code equals many bugs. So don't write any!!