Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for naming convention of UI controls for referencing in code-behind?

What is the best practice for naming UI controls (textboxes, drop-downs, etc.) on forms and reports for reference in the code-behind pages?

I develop a lot of reports and forms in my office. I have several web applications providing about 80+ "live" reports being generated from various and multiple data sources (Access, SQL, Oracle). These reports are considered "live" because they accept user set paramaters from a form, then query the database to produce a report based on the current information available.

So, the process starts with obtaining the values set by the user, passing those to the database query, receiving the dataset, and finally assigning the dataset to the report. In some cases, additional fields displayed on the report need to be calculated from the dataset before the report can be generated. This requires referencing the output controls on the report to assign the calculated value.

While I don't really care to use prefixes in my code for variables or member fields, I do use them to identify the UI controls. For example, txtFirstName to reference the report control to assign the data from the FirstName field in the dataset to the display control on the report. Is there a better practice for naming/referencing UI controls on forms and reports?

like image 387
Ronn Reeves Avatar asked Sep 21 '08 19:09

Ronn Reeves


1 Answers

For GUI controls, I suffix the variable name with the control name:

  • firstNameTextBox
  • lastNameTextBox
  • submitButton

This makes the relationship obvious between for example _firstName and firstNameTextBox.Text, and no one has to remember what the hungarian notation equivalent is. I would always choose clarity over brevity in naming variables.

like image 163
Arthur Vanderbilt Avatar answered Sep 22 '22 04:09

Arthur Vanderbilt