Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the Difference in Nomenclature?

Tags:

c#

asp.net

events

Why is it that in .aspx pages all events are preceded with "On" e.g. "OnClick", "OnCommand" and in the code-behind file they are referred "Click", "Command"? Just Naming Convention or is there some logical explanation?

like image 433
Alex Avatar asked Oct 15 '22 10:10

Alex


1 Answers

The names of the events themselves are Click, Change, etc... The internal methods to fire those events from code are prefixed with "On" as a naming convention. In ASP.NET markup, you use the attribute OnClick but what you're really doing is wiring a method to the "Click" event. Therefore, the method autogenerated for you by VS is ButtonName_Click. This method is internally passed as a delegate to the event itself.

like image 192
Chris Avatar answered Nov 15 '22 06:11

Chris