Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2003, 08:45 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old September 23rd, 2003, 08:14 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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
 
Old September 23rd, 2003, 08:48 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Exactly what I needed! Thanks!

J
 
Old May 12th, 2004, 09:18 AM
Registered User
 
Join Date: Aug 2003
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

 
Old May 12th, 2004, 12:22 PM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nm i worked it out...thx






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.