Should I rename the button event handler name?

When using Visual Studio (although this might ideally be the general case) and double-click on the button I created, the event handler code that is generated automatically uses the following signature:

Protected Sub btnSubmitRequest_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmitRequest.Click

End Sub

      

Is it better to leave the name of this method as it is, or rename it to something more descriptive like SubmitNewEmployeeRequest?

+1


source to share


3 answers


Create another method called SubmitNewEmployeeRequest

. In btnSubmitRequest_Click

call SubmitNewEmployeeRequest

. This is the most logical division of duties.



+7


source


Also, if you change the name of the button in the IDE before creating the handlers, the handlers will get better names by default. Currently your button name will be btnSubmitRequest, you can change it more specifically as btnSubmitNewEmployeeRequest and then generate a handler.

You have to name your controls and maintain consistency between controller and handler. I would call them in context of use, that is, if your in



  • Employee request form, then the button should be named SubmitRequest.
  • Create a Component Component, then the button should be more descriptive, like SubmitNewEmployeeRequest.
+2


source


Well, personally I leave it so that I can quickly see that it is an event handler, specifically a click event handler. However, I would tend to have only one line of code that calls (in this case, yours) the SubmitNewEmployeeRequest, because that can also be called from some context menu or fired in response to some other event.

+1


source







All Articles