Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 22nd, 2003, 08:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default Setting oncheckedchanged event in code behind file

Hi All,

Working in ASP.Net.

I have some radio buttons that I create with a For..Next loop in my code-behind file. What I want to know is does anyone know how to set the oncheckedchange event in the code behind file to run a procedure when a different radio button is checked?

I know how to do this in the form design, but I can't find anywhere how to in the code behind file. I am working in VB.Net, so please only post in this language. Thanks in advance.

J
Reply With Quote
  #2 (permalink)  
Old September 23rd, 2003, 08:14 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to create a handler in your code behind that conforms to the standard event handler signature, then when you build the radio button you add a handler to the oncheckchanged event (or any other for that matter).

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    Dim i As Integer
    Dim optRadioButton As RadioButton
    For i = 0 To 9
        optRadioButton = New RadioButton()
        optRadioButton.ID = "optRadioButton" & i.ToString
        optRadioButton.Text = "Radio button " & i.ToString
        optRadioButton.GroupName = "optRadioButton"
        optRadioButton.AutoPostBack = True
        AddHandler optRadioButton.CheckedChanged, AddressOf optRadioButton_onCheckedChanged
        plcRadios.Controls.Add(optRadioButton)
    Next
End Sub

Private Sub optRadioButton_onCheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Response.Write("you clicked on " & CType(sender, RadioButton).Text)
End Sub


Peter
Reply With Quote
  #3 (permalink)  
Old September 23rd, 2003, 08:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Exactly what I needed! Thanks!

J
Reply With Quote
  #4 (permalink)  
Old May 12th, 2004, 09:18 AM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i cant get the event to fire as described above

 Dim radioselectCell As New HtmlTableCell
 Dim selectrateRadio As New RadioButton

selectrateRadio.ID = i
selectrateRadio.GroupName = "selectrateRadio"
selectrateRadio.AutoPostBack = True
AddHandler selectrateRadio.CheckedChanged, AddressOf selectrateRadio_onCheckedChanged
radioselectCell.Controls.Add(selectrateRadio)

Private Sub selectrateRadio_onCheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Write("you clicked on " & CType(sender, RadioButton).Text)
    End Sub

any ideas ? thanks in advance

Reply With Quote
  #5 (permalink)  
Old May 12th, 2004, 12:22 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nm i worked it out...thx

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting onChange Event w/Dynamically Created Form rvanandel Javascript How-To 4 June 28th, 2007 08:10 AM
OnCheckedChanged trouble with codebehind method theycallmetish General .NET 1 July 9th, 2005 01:33 PM
setting event handled to true sajid C# 3 April 27th, 2005 12:02 PM
setting both onclick and ondblclick event handlers oranginalab Javascript How-To 3 November 25th, 2004 03:50 PM
Setting up the code download BenCh BOOK: ASP.NET Website Programming Problem-Design-Solution 1 June 11th, 2004 11:28 AM



All times are GMT -4. The time now is 07:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.