Button Click

Rajya

Member
Joined
Apr 15, 2005
Messages
22
Location
Calcutta, India
Programming Experience
1-3
Hello

Is there a way I can find out which button / control was accessed or clicked on a Windows Form?

Presently I am doing it manually by storing the info in a global variable as soon as a button is accessed.

Any advice will be appreciated :)
 
Put this into the page load

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 EventSource As String = Nothing

' If its a postback (not the initial page load)

If IsPostBack Then

EventSource = Request.Form("__EVENTTARGET")

' Which Event called the page load postback

Select Case EventSource

' if any of the options are selected

Case "Button1"

' Here is after the button was click
Case "DropDownList1"

' Here is after the dropdownlist was clicked

End Select

Else

' If its the initial page load

End If

' If its any page load
 
sorry to pop you're bubble there chime but windows form's do not have a page load event nor do they have any postback capabilities

rajya the only two methods that i can think of right now is to either
1) use a form level variable and set it on every button's click event (of which you're currently doing)

or

2) put all of the button's click event into one procedure:

VB.NET:
Private Sub Buttons_Click (...) Handles Button1.Click, Button2.Click, Button3.Click
  Dim myButton As Button = CType(sender, Button)
  Select Case myButton.Name 'find out which button it is
	Case "Button1"
	  'do code for the 1st button
	Case "Button2"
 	  'do code for the 2nd button
 	Case "Button3"
 	  'do code for the 3rd button
   End Select
End Sub

the handles clause is where you add more control's events (separeated by comma's) to the single click event
 
Back
Top