Adding a radion button at run time

R

Robert Bull

I am trying to add a radio button at runtime in an asp.net web form
but I keep getting the error message "type 'RadioButton' must be
placed inside a form tag with runat=server". I use the following code:

Dim rbYes As New RadioButton()
dim sStyle as string

sStyle = "POSITION:absolute; TOP: 250px; LEFT: 10px"
rbYes.Attributes.Add("style", sStyle)
rbYes.Attributes.Add("runat", "server")
Me.Controls.Add(rbYes)

It is as if the rbYes.Attributes.Add("runat", "server") line is not
being executed. Any help would be great. Thanks

-Rob
 
M

Martin Dechev

Hi, Rob,

Add the RadoiButton to the Controls collection of a PlaceHolder or a Panel
control that is already placed in the form of the page. In this way it will
end up inside the form.

Hope this helps
Martin
 
B

bruce barker

you have two bugs.

1) rbYes.Attributes.Add("runat", "server")

does nothing useful, as the attribute is meanless to the browser. the
attribute is only used when parsing the apsx file.

2) you are adding the control after the form control, so its outside the
form, it will never postback.

you should put a place holder on the page, and add the control to the
placeholders control collection


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top