Naming controls so your code stays readable
Control identifiers appear throughout your code. A careless name turns every reference into a puzzle.
A convention that works
- Start with the kind of control, shortened: txt, lbl, btn, ddl, grd.
- Follow with what it holds, in clear words: customerName, orderDate, totalPrice.
- Keep the same pattern everywhere so a reader can predict a name.
Markup
<asp:TextBox id="txtCustomerName" runat="server" />
<asp:Label id="lblOrderTotal" runat="server" />
<asp:Button id="btnSaveOrder" runat="server" />Why the prefix helps
In a long event handler you can tell at a glance whether a name is a text box, a label or a button. The type tells you what properties and methods are available, so you stop guessing.
Consistency beats cleverness. A plain convention applied everywhere is worth more than a perfect convention applied sometimes.
The page lifecycle gives your code a place to run. Start with the page load event.