Problem with RadioButton

I

Igor

RadioButton have property Checked (true or false).
If I make RadioButtons with code, without drawing by mouse than I have
problems. I write like this:

Dim rb(0 To 2) As RadioButton
Dim n As Integer

For n = 0 To 2
rb(n) = New RadioButton
rb(n).Text = "Text: " + CStr(n)
Panel1.Controls.Add(rb(n))
Next
Session("rb") = rb


Than I call this RadioButton array from session to other procedure:

Dim rb(0 To 2) As RadioButton
rb = Session("rb")
Response.Write(rb(0).Checked)
Response.Write(rb(1).Checked)
Response.Write(rb(2).Checked)


Problem is next: Every RadioButton have property Checked=False even when
user check some button. Text property is ok, but checked property is False
every time.

How to fix it?
 
C

Cor Ligthert [MVP]

Igor,

You are taking the behaviour from a checkbox.

There will only be one radiobutton in a control that can have the value
true..

(If you absolutely don't want checkboxes than you can set every radiobutton
in a groupbox (so for 3 buttons you have 3 groupboxes)). I would not do it,
because a radiobutton is a radiobutton wich is on or off.

Cor
 
I

Igor

(If you absolutely don't want checkboxes than you can set every
radiobutton in a groupbox (so for 3 buttons you have 3 groupboxes)). I
would not do it, because a radiobutton is a radiobutton wich is on or off.

Problem is not group property. It is not written in my code here, but it is
shorter code. I have one groupname for more checkboxes. Problem is that I
don't know how to pick checked property from radiobuttoncontrols which is
not added by mouse. Controls was addes by code in one procedure. In other
procedure I don't view this controll array. If I put this in session in
first procedure than radiobuttons are not checked because it is procedure
for drowing and user will check it on page after drowing (after program
exits from drowing procedure). How to view in other procedure which
radiobutton is checked?
 
I

Igor

Oh, no! Nobody knows this!
How to find some control which is added by code (new instance od object on
page). How to pick some property of some control which is added by user at
run time? Can I find it with FindControl method? How to use findcontrol
method? Please help!
 
C

Cor Ligthert [MVP]

Igor,

What your code probably does is setting the previous button of by setting
the next. There is not something as a group radiobutton. They are all
groupbuttons from the page as long as they are not set in a special group.

Cor
 

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

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top