Control array in design time

I

Igor

Can I create control array (like TextBox array) in design mode. In vb6 I
drow some control at the form and then I copy/paste controls. After that
every control have the same name, but they have propetry index which is
position of this control in the array. Can I do this in asp.net or I must
create control array with code?
 
D

DeveloperX

They're very different beasts. What are you trying to achieve, perhaps
we could suggest an alternative approach with some more detail.
 
I

Igor

DeveloperX said:
They're very different beasts. What are you trying to achieve, perhaps
we could suggest an alternative approach with some more detail.

I make radiobutton array. Then user click on some radiobutton. After that
program must see which of these radiobuttons have property checked=true. but
every radiobutton have property false. Look at 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)
rb(n).Groupname="Group1"
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?
 
E

Eliyahu Goldin

The controls you restore from the session have nothing to do with the values
you are getting in postbacks. You don't need to use session. Since you
create the radiobuttons dynamically, you need to re-create them on every
postback and then they will pick up the posted values. A good practice is to
re-create the dynamic controls in the Init event.

Here is a good article:
Dynamic Web Controls, Postbacks, and View State
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
D

DeveloperX

I'm not sure how familiar you are with asp.net, but could this be a
postback/viewstate issue? Where is the first snippet of code called and
where/when is the second bit called? The asp bod's will know, but I'm
guessing your code is being called twice overwriting the checked button
with a new button.
The easy way to check is pop a breakpoint on the first and second bits
of code and see if the first is hit between you checking a button and
the second bit of code being called.
 

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

Top