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

Control 'X' of type 'RadioButton' must be placed inside a form tag with runat=server.

P: n/a

I'm trying to create dynamic controls in ASP.Net. It's driving me
nuts. I keep getting the error:

Control '16' of type 'RadioButton' must be placed inside a form tag
with runat=server.

Dim Place1 As New PlaceHolder
Controls.Add(Place1)
For y = 1 To Choices.RecordCount
Choices.MoveTo(y)
Dim Radio As New RadioButton
Radio.ID = choices.ID
Radio.Text = choices.ChoiceText
Radio.GroupName = Q.ID
Place1.Controls.Add(Radio)

If I do Controls.Add(Radio) I get the above error. So I created a
placeholder in design view (there's nothing there since all page
content is dynamic). It added the radios but at the bottom of the
form. So I modified the code to dynamically create the placeholder
(as above). I STILL get this error.

Do I have to do a:
response.write("<FORM etc etc... runat=server>")
before every checbox creation?

Why doesn't it add the tags itself while its creating the controls?

How do I add a control without getting that needless error at every
turn?

Thanks!

Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Tom,

Try this instead of Controls.Add(Place1):

Me.FindControl("Form1").Controls.Add(Place1)

(provided your form is called Form1, obviously, but that's what it's
called by default).

You were adding the radiobuttons in the Page controls, but outside of
the Form controls.

Also note that "Me." is only here for demonstration purposes. You can
omit it, it's implicit.

HTH,

Michel

Tom wilson <ye*******@nospam.com> wrote in message news:<57********************************@4ax.com>. ..
I'm trying to create dynamic controls in ASP.Net. It's driving me
nuts. I keep getting the error:

Control '16' of type 'RadioButton' must be placed inside a form tag
with runat=server.

Dim Place1 As New PlaceHolder
Controls.Add(Place1)
For y = 1 To Choices.RecordCount
Choices.MoveTo(y)
Dim Radio As New RadioButton
Radio.ID = choices.ID
Radio.Text = choices.ChoiceText
Radio.GroupName = Q.ID
Place1.Controls.Add(Radio)

If I do Controls.Add(Radio) I get the above error. So I created a
placeholder in design view (there's nothing there since all page
content is dynamic). It added the radios but at the bottom of the
form. So I modified the code to dynamically create the placeholder
(as above). I STILL get this error.

Do I have to do a:
response.write("<FORM etc etc... runat=server>")
before every checbox creation?

Why doesn't it add the tags itself while its creating the controls?

How do I add a control without getting that needless error at every
turn?

Thanks!

Nov 19 '05 #2

P: n/a
When I add that line I get "Object reference not set to..." I've
tried it on its own page with nothing else but this:

Dim Place1 as new Placeholder
me.FindForm("TestForm").Controls.Add(Place1)

Same result. I have discovered that I can add a placeholder in design
view and it will accept control additions. I guess the whole problem
is that I cannot create a placeholder dynamically within the form
tags. I don't know why something so simple has to be so complicated.

On 8 Feb 2005 23:56:10 -0800, fd******@hotmail.com (fd123456) wrote:
Hi Tom,

Try this instead of Controls.Add(Place1):

Me.FindControl("Form1").Controls.Add(Place1)

(provided your form is called Form1, obviously, but that's what it's
called by default).

You were adding the radiobuttons in the Page controls, but outside of
the Form controls.

Also note that "Me." is only here for demonstration purposes. You can
omit it, it's implicit.

HTH,

Michel

Tom wilson <ye*******@nospam.com> wrote in message news:<57********************************@4ax.com>. ..
I'm trying to create dynamic controls in ASP.Net. It's driving me
nuts. I keep getting the error:

Control '16' of type 'RadioButton' must be placed inside a form tag
with runat=server.

Dim Place1 As New PlaceHolder
Controls.Add(Place1)
For y = 1 To Choices.RecordCount
Choices.MoveTo(y)
Dim Radio As New RadioButton
Radio.ID = choices.ID
Radio.Text = choices.ChoiceText
Radio.GroupName = Q.ID
Place1.Controls.Add(Radio)

If I do Controls.Add(Radio) I get the above error. So I created a
placeholder in design view (there's nothing there since all page
content is dynamic). It added the radios but at the bottom of the
form. So I modified the code to dynamically create the placeholder
(as above). I STILL get this error.

Do I have to do a:
response.write("<FORM etc etc... runat=server>")
before every checbox creation?

Why doesn't it add the tags itself while its creating the controls?

How do I add a control without getting that needless error at every
turn?

Thanks!


Nov 19 '05 #3

P: n/a
Couple things.

1. What is your page derived from to have a FindForm method?
2. Your form is probably called frmTestForm.

me.FindControl( "frmTestForm" ).Controls.Add( Place1 )

It really isn't that complicated; it is simply a matter of learning the
framework. Although I do wish MS would have exposed the internal Form
property they have. Perhaps this will be modified in 2.0.

bill

"Tom wilson" <ye*******@nospam.com> wrote in message
news:er********************************@4ax.com...
When I add that line I get "Object reference not set to..." I've
tried it on its own page with nothing else but this:

Dim Place1 as new Placeholder
me.FindForm("TestForm").Controls.Add(Place1)

Same result. I have discovered that I can add a placeholder in design
view and it will accept control additions. I guess the whole problem
is that I cannot create a placeholder dynamically within the form
tags. I don't know why something so simple has to be so complicated.

On 8 Feb 2005 23:56:10 -0800, fd******@hotmail.com (fd123456) wrote:
Hi Tom,

Try this instead of Controls.Add(Place1):

Me.FindControl("Form1").Controls.Add(Place1)

(provided your form is called Form1, obviously, but that's what it's
called by default).

You were adding the radiobuttons in the Page controls, but outside of
the Form controls.

Also note that "Me." is only here for demonstration purposes. You can
omit it, it's implicit.

HTH,

Michel

Tom wilson <ye*******@nospam.com> wrote in message news:<57********************************@4ax.com>. ..
I'm trying to create dynamic controls in ASP.Net. It's driving me
nuts. I keep getting the error:

Control '16' of type 'RadioButton' must be placed inside a form tag
with runat=server.

Dim Place1 As New PlaceHolder
Controls.Add(Place1)
For y = 1 To Choices.RecordCount
Choices.MoveTo(y)
Dim Radio As New RadioButton
Radio.ID = choices.ID
Radio.Text = choices.ChoiceText
Radio.GroupName = Q.ID
Place1.Controls.Add(Radio)

If I do Controls.Add(Radio) I get the above error. So I created a
placeholder in design view (there's nothing there since all page
content is dynamic). It added the radios but at the bottom of the
form. So I modified the code to dynamically create the placeholder
(as above). I STILL get this error.

Do I have to do a:
response.write("<FORM etc etc... runat=server>")
before every checbox creation?

Why doesn't it add the tags itself while its creating the controls?

How do I add a control without getting that needless error at every
turn?

Thanks!

Nov 19 '05 #4

P: n/a
1 - How do I find that out? The Class is called "TestForm". It
appears to inherit from "MyApp.TestForm". Is that what I need?
Not complicated? This is a re-write of a survey application
originally done in asp. For that method, it was as simple as one line
of HTML to create a textbox and response.write the text/html. With
this I have to:

1 - Manually add a placeholder to the empty form. I can't create one
dynamically, everyt method I've tried fails.

2 - Create a set of control arrays for each type of control; checkbox,
radio, etc.

3 - Redim Preserve each array as the number of controls increases as
they are created. I hope 500 radios don't eat too much memory.

4 - Create the control, takes about 5 lines of code not including the
array tracking.

5 - Add the newly created control to the placeholder.

....and everything must be a control. Text? HTML? They have to be
defined as LiteralControl(s) and added in sequence. I remember when
it was called "response.write" but if I do that, all the text is at
the top of the page and the controls underneath because response.write
doesn't add to a placeholder. I swear if I have to do tables my head
will explode.

Yes, it's that complicated.

Sorry about the rant, it's been 3 days at this with little progress.
I do very much appreciate your input.


On Wed, 9 Feb 2005 10:19:48 -0600, "William F. Robertson, Jr."
<th****@nameht.org> wrote:
Couple things.

1. What is your page derived from to have a FindForm method?
2. Your form is probably called frmTestForm.

me.FindControl( "frmTestForm" ).Controls.Add( Place1 )

It really isn't that complicated; it is simply a matter of learning the
framework. Although I do wish MS would have exposed the internal Form
property they have. Perhaps this will be modified in 2.0.

bill

"Tom wilson" <ye*******@nospam.com> wrote in message
news:er********************************@4ax.com.. .
When I add that line I get "Object reference not set to..." I've
tried it on its own page with nothing else but this:

Dim Place1 as new Placeholder
me.FindForm("TestForm").Controls.Add(Place1)

Same result. I have discovered that I can add a placeholder in design
view and it will accept control additions. I guess the whole problem
is that I cannot create a placeholder dynamically within the form
tags. I don't know why something so simple has to be so complicated.

On 8 Feb 2005 23:56:10 -0800, fd******@hotmail.com (fd123456) wrote:
>Hi Tom,
>
>Try this instead of Controls.Add(Place1):
>
>Me.FindControl("Form1").Controls.Add(Place1)
>
>(provided your form is called Form1, obviously, but that's what it's
>called by default).
>
>You were adding the radiobuttons in the Page controls, but outside of
>the Form controls.
>
>Also note that "Me." is only here for demonstration purposes. You can
>omit it, it's implicit.
>
>HTH,
>
>Michel
>
>Tom wilson <ye*******@nospam.com> wrote in messagenews:<57********************************@4ax.com> ... >> I'm trying to create dynamic controls in ASP.Net. It's driving me
>> nuts. I keep getting the error:
>>
>> Control '16' of type 'RadioButton' must be placed inside a form tag
>> with runat=server.
>>
>> Dim Place1 As New PlaceHolder
>> Controls.Add(Place1)
>> For y = 1 To Choices.RecordCount
>> Choices.MoveTo(y)
>> Dim Radio As New RadioButton
>> Radio.ID = choices.ID
>> Radio.Text = choices.ChoiceText
>> Radio.GroupName = Q.ID
>> Place1.Controls.Add(Radio)
>>
>> If I do Controls.Add(Radio) I get the above error. So I created a
>> placeholder in design view (there's nothing there since all page
>> content is dynamic). It added the radios but at the bottom of the
>> form. So I modified the code to dynamically create the placeholder
>> (as above). I STILL get this error.
>>
>> Do I have to do a:
>> response.write("<FORM etc etc... runat=server>")
>> before every checbox creation?
>>
>> Why doesn't it add the tags itself while its creating the controls?
>>
>> How do I add a control without getting that needless error at every
>> turn?
>>
>> Thanks!


Nov 19 '05 #5

P: n/a
1 - look at the aspx side of the page.

You will see the form element.

<form runat="server" id="myForm">

You can get this control by typing
Form = Page.FindControl( "myForm" );

Notice the parameter to FindControl is the ID of the control. If ID isn't
there, then assign it one.

ASP.NET is a completely different way of html generation. You really can't
think of things such as, "in asp I would just do document.write, etc." You
must think of terms of controls.

I really don't know enough about your requirements to tell you how and what
you should be doing, but I wish you the best of luck. There are several
ways to accomplish what you are trying to do.

Is the entire page dynamic? What determines the content? How much state
information should be maintained.

bill

You can always access the Request.Forms("txtName") and get the posted values
without worry about setting up control trees.
Also, if you really like the asp rendering module, you can always override
the Page.Render method and write out the html using Response.Write.
Although I don't think anyone on this board would recommend that approach.


"Tom wilson" <ye*******@nospam.com> wrote in message
news:0c********************************@4ax.com...
1 - How do I find that out? The Class is called "TestForm". It
appears to inherit from "MyApp.TestForm". Is that what I need?
Not complicated? This is a re-write of a survey application
originally done in asp. For that method, it was as simple as one line
of HTML to create a textbox and response.write the text/html. With
this I have to:

1 - Manually add a placeholder to the empty form. I can't create one
dynamically, everyt method I've tried fails.

2 - Create a set of control arrays for each type of control; checkbox,
radio, etc.

3 - Redim Preserve each array as the number of controls increases as
they are created. I hope 500 radios don't eat too much memory.

4 - Create the control, takes about 5 lines of code not including the
array tracking.

5 - Add the newly created control to the placeholder.

...and everything must be a control. Text? HTML? They have to be
defined as LiteralControl(s) and added in sequence. I remember when
it was called "response.write" but if I do that, all the text is at
the top of the page and the controls underneath because response.write
doesn't add to a placeholder. I swear if I have to do tables my head
will explode.

Yes, it's that complicated.

Sorry about the rant, it's been 3 days at this with little progress.
I do very much appreciate your input.


On Wed, 9 Feb 2005 10:19:48 -0600, "William F. Robertson, Jr."
<th****@nameht.org> wrote:
Couple things.

1. What is your page derived from to have a FindForm method?
2. Your form is probably called frmTestForm.

me.FindControl( "frmTestForm" ).Controls.Add( Place1 )

It really isn't that complicated; it is simply a matter of learning the
framework. Although I do wish MS would have exposed the internal Form
property they have. Perhaps this will be modified in 2.0.

bill

"Tom wilson" <ye*******@nospam.com> wrote in message
news:er********************************@4ax.com.. .
When I add that line I get "Object reference not set to..." I've
tried it on its own page with nothing else but this:

Dim Place1 as new Placeholder
me.FindForm("TestForm").Controls.Add(Place1)

Same result. I have discovered that I can add a placeholder in design
view and it will accept control additions. I guess the whole problem
is that I cannot create a placeholder dynamically within the form
tags. I don't know why something so simple has to be so complicated.

On 8 Feb 2005 23:56:10 -0800, fd******@hotmail.com (fd123456) wrote:

>Hi Tom,
>
>Try this instead of Controls.Add(Place1):
>
>Me.FindControl("Form1").Controls.Add(Place1)
>
>(provided your form is called Form1, obviously, but that's what it's
>called by default).
>
>You were adding the radiobuttons in the Page controls, but outside of
>the Form controls.
>
>Also note that "Me." is only here for demonstration purposes. You can
>omit it, it's implicit.
>
>HTH,
>
>Michel
>
>Tom wilson <ye*******@nospam.com> wrote in message

news:<57********************************@4ax.com> ...
>> I'm trying to create dynamic controls in ASP.Net. It's driving me
>> nuts. I keep getting the error:
>>
>> Control '16' of type 'RadioButton' must be placed inside a form tag
>> with runat=server.
>>
>> Dim Place1 As New PlaceHolder
>> Controls.Add(Place1)
>> For y = 1 To Choices.RecordCount
>> Choices.MoveTo(y)
>> Dim Radio As New RadioButton
>> Radio.ID = choices.ID
>> Radio.Text = choices.ChoiceText
>> Radio.GroupName = Q.ID
>> Place1.Controls.Add(Radio)
>>
>> If I do Controls.Add(Radio) I get the above error. So I created a
>> placeholder in design view (there's nothing there since all page
>> content is dynamic). It added the radios but at the bottom of the
>> form. So I modified the code to dynamically create the placeholder
>> (as above). I STILL get this error.
>>
>> Do I have to do a:
>> response.write("<FORM etc etc... runat=server>")
>> before every checbox creation?
>>
>> Why doesn't it add the tags itself while its creating the controls?
>>
>> How do I add a control without getting that needless error at every
>> turn?
>>
>> Thanks!

Nov 19 '05 #6

P: n/a
Ok, I have the page working using a single static placeholder.
That'll do the job. 100% of the content is retrieved from a SQL
Server database and everything down to the text is generated
dynamcially. I'm just fighting with the session object now. :)

I appreciate your help. Thanks!
On Wed, 9 Feb 2005 13:50:16 -0600, "William F. Robertson, Jr."
<th****@nameht.org> wrote:
1 - look at the aspx side of the page.

You will see the form element.

<form runat="server" id="myForm">

You can get this control by typing
Form = Page.FindControl( "myForm" );

Notice the parameter to FindControl is the ID of the control. If ID isn't
there, then assign it one.

ASP.NET is a completely different way of html generation. You really can't
think of things such as, "in asp I would just do document.write, etc." You
must think of terms of controls.

I really don't know enough about your requirements to tell you how and what
you should be doing, but I wish you the best of luck. There are several
ways to accomplish what you are trying to do.

Is the entire page dynamic? What determines the content? How much state
information should be maintained.

bill

You can always access the Request.Forms("txtName") and get the posted values
without worry about setting up control trees.
Also, if you really like the asp rendering module, you can always override
the Page.Render method and write out the html using Response.Write.
Although I don't think anyone on this board would recommend that approach.


"Tom wilson" <ye*******@nospam.com> wrote in message
news:0c********************************@4ax.com.. .
1 - How do I find that out? The Class is called "TestForm". It
appears to inherit from "MyApp.TestForm". Is that what I need?
Not complicated? This is a re-write of a survey application
originally done in asp. For that method, it was as simple as one line
of HTML to create a textbox and response.write the text/html. With
this I have to:

1 - Manually add a placeholder to the empty form. I can't create one
dynamically, everyt method I've tried fails.

2 - Create a set of control arrays for each type of control; checkbox,
radio, etc.

3 - Redim Preserve each array as the number of controls increases as
they are created. I hope 500 radios don't eat too much memory.

4 - Create the control, takes about 5 lines of code not including the
array tracking.

5 - Add the newly created control to the placeholder.

...and everything must be a control. Text? HTML? They have to be
defined as LiteralControl(s) and added in sequence. I remember when
it was called "response.write" but if I do that, all the text is at
the top of the page and the controls underneath because response.write
doesn't add to a placeholder. I swear if I have to do tables my head
will explode.

Yes, it's that complicated.

Sorry about the rant, it's been 3 days at this with little progress.
I do very much appreciate your input.


On Wed, 9 Feb 2005 10:19:48 -0600, "William F. Robertson, Jr."
<th****@nameht.org> wrote:
>Couple things.
>
>1. What is your page derived from to have a FindForm method?
>2. Your form is probably called frmTestForm.
>
>me.FindControl( "frmTestForm" ).Controls.Add( Place1 )
>
>It really isn't that complicated; it is simply a matter of learning the
>framework. Although I do wish MS would have exposed the internal Form
>property they have. Perhaps this will be modified in 2.0.
>
>bill
>
>"Tom wilson" <ye*******@nospam.com> wrote in message
>news:er********************************@4ax.com.. .
>> When I add that line I get "Object reference not set to..." I've
>> tried it on its own page with nothing else but this:
>>
>> Dim Place1 as new Placeholder
>> me.FindForm("TestForm").Controls.Add(Place1)
>>
>> Same result. I have discovered that I can add a placeholder in design
>> view and it will accept control additions. I guess the whole problem
>> is that I cannot create a placeholder dynamically within the form
>> tags. I don't know why something so simple has to be so complicated.
>>
>>
>>
>> On 8 Feb 2005 23:56:10 -0800, fd******@hotmail.com (fd123456) wrote:
>>
>> >Hi Tom,
>> >
>> >Try this instead of Controls.Add(Place1):
>> >
>> >Me.FindControl("Form1").Controls.Add(Place1)
>> >
>> >(provided your form is called Form1, obviously, but that's what it's
>> >called by default).
>> >
>> >You were adding the radiobuttons in the Page controls, but outside of
>> >the Form controls.
>> >
>> >Also note that "Me." is only here for demonstration purposes. You can
>> >omit it, it's implicit.
>> >
>> >HTH,
>> >
>> >Michel
>> >
>> >Tom wilson <ye*******@nospam.com> wrote in message
>news:<57********************************@4ax.com> ...
>> >> I'm trying to create dynamic controls in ASP.Net. It's driving me
>> >> nuts. I keep getting the error:
>> >>
>> >> Control '16' of type 'RadioButton' must be placed inside a form tag
>> >> with runat=server.
>> >>
>> >> Dim Place1 As New PlaceHolder
>> >> Controls.Add(Place1)
>> >> For y = 1 To Choices.RecordCount
>> >> Choices.MoveTo(y)
>> >> Dim Radio As New RadioButton
>> >> Radio.ID = choices.ID
>> >> Radio.Text = choices.ChoiceText
>> >> Radio.GroupName = Q.ID
>> >> Place1.Controls.Add(Radio)
>> >>
>> >> If I do Controls.Add(Radio) I get the above error. So I created a
>> >> placeholder in design view (there's nothing there since all page
>> >> content is dynamic). It added the radios but at the bottom of the
>> >> form. So I modified the code to dynamically create the placeholder
>> >> (as above). I STILL get this error.
>> >>
>> >> Do I have to do a:
>> >> response.write("<FORM etc etc... runat=server>")
>> >> before every checbox creation?
>> >>
>> >> Why doesn't it add the tags itself while its creating the controls?
>> >>
>> >> How do I add a control without getting that needless error at every
>> >> turn?
>> >>
>> >> Thanks!
>>
>


Nov 19 '05 #7

P: n/a
Glad to here you got it "working'.

If you give up fighting the Session, post another entry and you will surely
be helped...

bill

"Tom wilson" <ye*******@nospam.com> wrote in message
news:lb********************************@4ax.com...
Ok, I have the page working using a single static placeholder.
That'll do the job. 100% of the content is retrieved from a SQL
Server database and everything down to the text is generated
dynamcially. I'm just fighting with the session object now. :)

I appreciate your help. Thanks!
On Wed, 9 Feb 2005 13:50:16 -0600, "William F. Robertson, Jr."
<th****@nameht.org> wrote:
1 - look at the aspx side of the page.

You will see the form element.

<form runat="server" id="myForm">

You can get this control by typing
Form = Page.FindControl( "myForm" );

Notice the parameter to FindControl is the ID of the control. If ID isn'tthere, then assign it one.

ASP.NET is a completely different way of html generation. You really can'tthink of things such as, "in asp I would just do document.write, etc." Youmust think of terms of controls.

I really don't know enough about your requirements to tell you how and whatyou should be doing, but I wish you the best of luck. There are several
ways to accomplish what you are trying to do.

Is the entire page dynamic? What determines the content? How much state
information should be maintained.

bill

You can always access the Request.Forms("txtName") and get the posted valueswithout worry about setting up control trees.
Also, if you really like the asp rendering module, you can always overridethe Page.Render method and write out the html using Response.Write.
Although I don't think anyone on this board would recommend that approach.

"Tom wilson" <ye*******@nospam.com> wrote in message
news:0c********************************@4ax.com.. .
1 - How do I find that out? The Class is called "TestForm". It
appears to inherit from "MyApp.TestForm". Is that what I need?
Not complicated? This is a re-write of a survey application
originally done in asp. For that method, it was as simple as one line
of HTML to create a textbox and response.write the text/html. With
this I have to:

1 - Manually add a placeholder to the empty form. I can't create one
dynamically, everyt method I've tried fails.

2 - Create a set of control arrays for each type of control; checkbox,
radio, etc.

3 - Redim Preserve each array as the number of controls increases as
they are created. I hope 500 radios don't eat too much memory.

4 - Create the control, takes about 5 lines of code not including the
array tracking.

5 - Add the newly created control to the placeholder.

...and everything must be a control. Text? HTML? They have to be
defined as LiteralControl(s) and added in sequence. I remember when
it was called "response.write" but if I do that, all the text is at
the top of the page and the controls underneath because response.write
doesn't add to a placeholder. I swear if I have to do tables my head
will explode.

Yes, it's that complicated.

Sorry about the rant, it's been 3 days at this with little progress.
I do very much appreciate your input.


On Wed, 9 Feb 2005 10:19:48 -0600, "William F. Robertson, Jr."
<th****@nameht.org> wrote:

>Couple things.
>
>1. What is your page derived from to have a FindForm method?
>2. Your form is probably called frmTestForm.
>
>me.FindControl( "frmTestForm" ).Controls.Add( Place1 )
>
>It really isn't that complicated; it is simply a matter of learning the >framework. Although I do wish MS would have exposed the internal Form
>property they have. Perhaps this will be modified in 2.0.
>
>bill
>
>"Tom wilson" <ye*******@nospam.com> wrote in message
>news:er********************************@4ax.com.. .
>> When I add that line I get "Object reference not set to..." I've
>> tried it on its own page with nothing else but this:
>>
>> Dim Place1 as new Placeholder
>> me.FindForm("TestForm").Controls.Add(Place1)
>>
>> Same result. I have discovered that I can add a placeholder in design >> view and it will accept control additions. I guess the whole problem >> is that I cannot create a placeholder dynamically within the form
>> tags. I don't know why something so simple has to be so complicated. >>
>>
>>
>> On 8 Feb 2005 23:56:10 -0800, fd******@hotmail.com (fd123456) wrote:
>>
>> >Hi Tom,
>> >
>> >Try this instead of Controls.Add(Place1):
>> >
>> >Me.FindControl("Form1").Controls.Add(Place1)
>> >
>> >(provided your form is called Form1, obviously, but that's what it's >> >called by default).
>> >
>> >You were adding the radiobuttons in the Page controls, but outside of >> >the Form controls.
>> >
>> >Also note that "Me." is only here for demonstration purposes. You can >> >omit it, it's implicit.
>> >
>> >HTH,
>> >
>> >Michel
>> >
>> >Tom wilson <ye*******@nospam.com> wrote in message
>news:<57********************************@4ax.com> ...
>> >> I'm trying to create dynamic controls in ASP.Net. It's driving me >> >> nuts. I keep getting the error:
>> >>
>> >> Control '16' of type 'RadioButton' must be placed inside a form tag >> >> with runat=server.
>> >>
>> >> Dim Place1 As New PlaceHolder
>> >> Controls.Add(Place1)
>> >> For y = 1 To Choices.RecordCount
>> >> Choices.MoveTo(y)
>> >> Dim Radio As New RadioButton
>> >> Radio.ID = choices.ID
>> >> Radio.Text = choices.ChoiceText
>> >> Radio.GroupName = Q.ID
>> >> Place1.Controls.Add(Radio)
>> >>
>> >> If I do Controls.Add(Radio) I get the above error. So I created a >> >> placeholder in design view (there's nothing there since all page
>> >> content is dynamic). It added the radios but at the bottom of the >> >> form. So I modified the code to dynamically create the placeholder >> >> (as above). I STILL get this error.
>> >>
>> >> Do I have to do a:
>> >> response.write("<FORM etc etc... runat=server>")
>> >> before every checbox creation?
>> >>
>> >> Why doesn't it add the tags itself while its creating the controls? >> >>
>> >> How do I add a control without getting that needless error at every >> >> turn?
>> >>
>> >> Thanks!
>>
>

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.