sainavya1215
asked on
Vb.net Textbox Command Button
Windows form
============
I hve a windows form with 2 TextBoxes and 2 Cancel buttons. As a textboxes value can be cancelled .
I populate the data from the dataset (well i dont bind it as its not ncesssary)
in both the textboxes. User can click cancel to cancel a value in textbox where I update the database saying that line has been cancelled.
How would we know that if cancel button pressed corresponds to textbox1 or textbox2
Textbox1 cancelButton
Textbox2 cancelButton
Textbox3 cancelButton
Can a simple example be shown ? thanks in advance
============
I hve a windows form with 2 TextBoxes and 2 Cancel buttons. As a textboxes value can be cancelled .
I populate the data from the dataset (well i dont bind it as its not ncesssary)
in both the textboxes. User can click cancel to cancel a value in textbox where I update the database saying that line has been cancelled.
How would we know that if cancel button pressed corresponds to textbox1 or textbox2
Textbox1 cancelButton
Textbox2 cancelButton
Textbox3 cancelButton
Can a simple example be shown ? thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When an event handler is fired, it is passed an Object called "sender". This is the object that triggered the event.
If you know what type of object it is, you can use the CTYPE function to cast the generic Object into the object that triggered the event.
Solution 2 provided by arif_egbal simply says this:
Private Sub ButtonClicks(sender As Object, e as EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
Select Case CType(sender, Button).Name ' This determines WHAT button the user clicked.
Case "Button1"
Case "Button2"
Case "Button3"
End Sub
This technique allows you to reduce code by using the same event handler to handle multiple events from objects on your form.
Hope that helps.
If you know what type of object it is, you can use the CTYPE function to cast the generic Object into the object that triggered the event.
Solution 2 provided by arif_egbal simply says this:
Private Sub ButtonClicks(sender As Object, e as EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
Select Case CType(sender, Button).Name ' This determines WHAT button the user clicked.
Case "Button1"
Case "Button2"
Case "Button3"
End Sub
This technique allows you to reduce code by using the same event handler to handle multiple events from objects on your form.
Hope that helps.
ASKER