Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

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.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.