Solved

Setting an event for an array of radio buttons

Posted on 2011-09-07
7
259 Views
Last Modified: 2012-06-21
My code dynamically creates radio buttons.  How do add a handler to that to point to code?
Dim rbA(16) As RadioButton
        Dim rbH(16) As RadioButton

        For iLoop = 1 To 16

            rbA(iLoop) = New RadioButton
            rbH(iLoop) = New RadioButton

            With rbA(iLoop)

                .Text = "TEST"
                .Checked = False
                .GroupName = "GroupA" & iLoop
                .ID = "Here" & iLoop
                .BackColor = Drawing.Color.SteelBlue

            End With

            Panel1.Controls.Add(rbA(iLoop))

Open in new window

0
Comment
Question by:NOTBOB90
  • 4
  • 2
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36499003
Use the AddHanler keyword:
Dim rbA(16) As RadioButton
        Dim rbH(16) As RadioButton

        For iLoop = 1 To 16

            rbA(iLoop) = New RadioButton
            rbH(iLoop) = New RadioButton

            AddHandler rbA(iLoop).CheckChanged, AddressOf Radio_CheckChanged
            AddHandler rbH(iLoop).CheckChanged, AddressOf Radio_CheckChanged

            With rbA(iLoop)

                .Text = "TEST"
                .Checked = False
                .GroupName = "GroupA" & iLoop
                .ID = "Here" & iLoop
                .BackColor = Drawing.Color.SteelBlue

            End With

            Panel1.Controls.Add(rbA(iLoop))

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 50 total points
ID: 36499011
P.S.

The syntax for AddHandler is:

AddHandler obj.EventName, AddressOf EventHandlerFunctionName
0
 

Author Comment

by:NOTBOB90
ID: 36499025
This is on the web, not .net.  Will it work like that there?
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36499118
This is on the web, not .net.  Will it work like that there?
It will add a server-side event handler--though you still need to code the actual handler function. If you want a client-side handler (i.e. javascript), then you would need to use the ScriptManager.
0
 

Author Comment

by:NOTBOB90
ID: 36499827

WHen I do this:

AddHandler rbH(iLoop).CheckChanged, AddressOf proRadioClick

I get this error hovering over checkchanged

checkchanged is not an event of system.web.ui..webcontrols.radiobutton
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36499977
I was just throwing an event out as an example. The correct name is CheckedChanged. See here for more details.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question