Which checkbox was checked?

  • Thread starter Thread starter Jim M
  • Start date Start date
J

Jim M

I have added 10 checkboxes to my aspx web page. Is there anyway to figure
out which checkbox caused the postback without having 10 different "handles
routines".

Thanks in advance.
 
Hi Jim,

Buttons but the method is the same I think,
(I also have it from checkboxes on a winform, from that I made this)

I hope this helps?

Cor
\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim mybutton(31) As Button
Dim i As Integer
For i = 0 To New Date().DaysInMonth _
(New Date().Year, New Date().Month) - 1
mybutton(i) = New Button
mybutton(i).BackColor = Drawing.Color.White
mybutton(i).Text = (i + 1).ToString
mybutton(i).Width = New Unit(30)
Me.Panel1.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
If (i + 1) Mod 5 = 0 Then
Me.Panel1.Controls.Add(New LiteralControl("<BR>"))
End If
Next
End Sub
Private Sub mybutton_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mylabel As New Label
Me.Panel1.Controls.Add(New LiteralControl("<BR><BR>"))
Me.Panel1.Controls.Add(mylabel)
mylabel.Text = "The day is: " & DirectCast(sender, Button).Text
End Sub
///
Link
http://msdn.microsoft.com/library/d...l/vbtskcodeexampleaddingcontrolsatruntime.asp
 
Your event handler sub can handle events for more than one control (as long
as they have the same parameters)

ie.

Public Sub MyHandler (ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles checkbox1.checkchanged, checkbox2.checkchanged

'From within here, you can see what the sender is

if sender Is checbox1 then
'blah blah
elseif sender is checkbox2 then
'rhubarb rhubarb
endif

End Sub
 
Back
Top