1

How can I get the selected value of a radioButtonList if this is created dynamically? I know that a dynamic control must be recreated on each postback but, is there a trick to solve this scenario?

Thanks in advance for the help.

Argons
  • 445
  • 1
  • 6
  • 23

2 Answers2

0

Make sure you're creating the listitems in Page_Init - not Page_Load. The Viewstate will be hooked up correctly and you should be able to get the SelectedValue as normal.

(Also, if your RBL is in a usercontrol, that any values/objects needed for the RBL are loaded in that Init as well, that's what fooled me for a long itme.)

JonK
  • 622
  • 7
  • 13
0

You'd get a reference to your RadioButtonList after the postback and would get the value the same way you'd get if it was created statically.

Take a look here:

Accessing controls created dynamically (c#) (take a look at the question to see how to get a reference to the dynamically created control)

It just happens that the above answer has a RadioButtonList example.

Community
  • 1
  • 1
Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480