Adding a radion button at run time

  • Thread starter Thread starter Robert Bull
  • Start date Start date
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
 
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
 
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)
 
Back
Top