Adding a radion button at run time

Discussion in 'ASP .Net' started by Robert Bull, Apr 21, 2004.

  1. Robert Bull

    Robert Bull Guest

    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
    Robert Bull, Apr 21, 2004
    #1
    1. Advertising

  2. 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
    "Robert Bull" <> wrote in message
    news:...
    > 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
    Martin Dechev, Apr 21, 2004
    #2
    1. Advertising

  3. Robert Bull

    bruce barker Guest

    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)




    "Robert Bull" <> wrote in message
    news:...
    > 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
    bruce barker, Apr 21, 2004
    #3
  4. Robert Bull

    Robert Bull Guest

    Thanks Bruce...I used a panel instead and it worked great!

    -Rob
    Robert Bull, Apr 23, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Dippold

    Adding Textbox to table at run time

    Ken Dippold, Aug 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,727
    entdevguy
    Aug 24, 2004
  2. puja
    Replies:
    1
    Views:
    465
    Eliyahu Goldin
    May 21, 2006
  3. George Ter-Saakov
    Replies:
    1
    Views:
    405
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Nov 11, 2006
  4. flamesrock
    Replies:
    8
    Views:
    434
    Hendrik van Rooyen
    Nov 24, 2006
  5. Pierre Yves
    Replies:
    2
    Views:
    469
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page