By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,668 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,668 IT Pros & Developers. It's quick & easy.

emergency

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I think you can try to remove

protected RadioButton radio;

If you already defined radio as a control in form, how can you add it again
with

this.controls.add(radio);
"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

Nov 16 '05 #2

P: n/a
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)

"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

Nov 16 '05 #3

P: n/a


Do you know how can I make a small portion of a page scrolling up/down
automatically? In Natscape, there is Layer concept that looks can be
used to accomplish this problem. Is there a simiar in Windows?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

P: n/a


Thank you, CBretana
You are right. the object of 'this' is not a Form's object.
I resoved this problem by adding a asp table and add radio buttons in
table's cells.

Shawn

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.