I believe you can't add radio button controls to the Page.Controls... You
must add to a Form.controls collection
HtmlForm HTMLF = new HtmlForm();
foreach(Control ctl in this.Controls)
{
if (ctl.GetType() == HTMLF.GetType())
{
//now that we have found the form control, we can add the
radiobutton
radio = new RadioButton();
radio.Text = "new lable";
ctl.Controls.Add(radio);
(untested)
[quoted text, click to view] "Shawn Zheng" wrote:
> Help!!!
> I want to dynamicaly create controls in ASP.NET Web form in the following
> code.
>
> protected RadioButton radio;
>
> private void Page_Load()
> {
> radio = new RadioButton();
> radio.Text = "new lable";
> this.controls.add(radio);
> }
>
> Why I can not do it in this way. the error says the control is not added to
> form.
> How do I resove it. It seems this.controls not belong to the web form. Is it
> strange?
>
> Shawn
>
>