Solved

Setting an event for an array of radio buttons

Posted on 2011-09-07
7
256 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Runtime Error 2 28
Error in JQuery 5 38
Entity Framework 7 31
Show/Hide ASP.NET controls with JQuery best practices 3 17
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now