Tuesday, August 16, 2011

ASP.Net Coding Standards


Naming and Capitalisation


IdentifierCaseExamplesAdditional NotesDetailed Info
ClassPascalPerson, BankVault, SMSMessage, DeptClass names should be based on "objects" or "real things" and should generally be nouns.
MSDN site - more details
MethodPascalGetDetails, UpdateStoreMethods should use verbsor verb phrases.
ParametercamelpersonName, bankCode
MSDN site - more details
InterfacePascal with "I" prefixIDisposableOne of the few times when prefixing is adopted.
MSDN site - more details
Property
Associated private member variable
Pascal
_camelCase
ForeColor, BackColor
_foreColor, _backColor
Use underscore camel casing for the private member variables, but keep the names the same as associated property accessors.
MSDN site - more details
Exception ClassPascal with "Exception" suffixWebException, SMSException
EventPascal plus optional "EventHandler" suffix where relevantbtnSubmit_Click, Painting, Click, Clicked, MyEventHandlerVS uses underscores to separate an object from its event. Be careful with tense (pre/past), e.g. a Close event that can be canceled should have a Closing event and a Closed event. MS also recommend adding the "EventHandler" suffix where thought needed.
MSDN site - more details



Naming Conventions for ASP.NET Controls


Control NameExamplePrefix
LabellblNamelbl
TextBoxtxtNametxt
GridViewgvResultgv
ButtonbtnSavebtn
ImageButtonibtnSaveibtn
HyperlinklnkHomePagelnk
DropDownListddlCompanyddl
ListBoxlstCompanylst
DataListdlstAddressdlst
RepeaterrepSectionrep
CheckboxchkMailListchk
CheckBoxListchkAddresschk
RadioButtonrdoSexrdo
RadioButtonListrdoAgeGrouprdo
ImageimgLogoimg
PanelpanSectionpan
PlaceHolderplhHeaderplh
CalendercalMyDatecal
AdrotatoradrBanneradr
TabletblResultstbl
[All]ValidatorsvalCreditCardNumberval
ValidationSummaryvalsErrorsvals


Table - 1: Naming Conventions


WebForm ControlsPrefixWebForm ControlsPrefix
ButtonbtnRadioButtonrad
CheckBox
chk
RadioButtonList
radl
CheckBoxList
chkl
TextBox
txt
DataGrid
dgrd
RequiredFieldValidator
valr
DataList
dlst
CompareValidator
valc
DrpDownList
drop
RangeValidator
valg
Image
img
RegularExpressionValidator
vale
ImageButton
ibtn
CustomValidator
valx
Label
lbl
ValidationSummary
vals
LinkButton
lbtn
Table
tbl
ListBox
lst
Calendar
cal


In general, naming ASP.NET controls is made using Camel Case naming convention, where the prefix of the name is the abbreviation of the control type name.

AbbreviationASP.NET Control
STANDARD CONTROLS
btnButton
cbCheckBox
cblCheckBoxList
ddlDropDownList
fuFileUpload
hdnHiddenField
lnkHyperlink
imgImage
ibtn(btn)ImageButton
lblLabel
lbtn(btn)LinkButton
lbListBox
litLiteral
mvMultiView
pnlPanel
phPlaceHolder
rbRadioButton
rblRadioButtonList
tblTable
txtTextBox
vView
DATA CONTROLS
dtlDataList
dpDataPager
dtvDetailsView
etsEntityDataSource
fvFormView
gvGridView
ldsLinqDataSource
lvListView
odsObjectDataSource
qeQueryExtender
rptRepeater
smdSiteMapDataSource
sdsSqlDataSource
xdsXmlDataSource
VALIDATION CONTROLS
cpvCompareValidator
ctvCustomValidator
rvRangeValidator
revRegularExpressionValidator
rfvRequiredFieldValidator
vsValidationSummary





C# type nameVisual Basic type nameJScript type nameVisual C++ type nameIlasm.exe representationCLR type name
sbyte
SByte
sByte
char
int8
SByte
byte
Byte
byte
unsigned char
unsigned int8
Byte
short
Short
short
short
int16
Int16
ushort
UInt16
ushort
unsigned short
unsigned int16
UInt16
int
Integer
int
int
int32
Int32
uint
UInt32
uint
unsigned int
unsigned int32
UInt32
long
Long
long
__int64
int64
Int64
ulong
UInt64
ulong
unsigned __int64
unsigned int64
UInt64
float
Single
float
float
float32
Single
double
Double
double
double
float64
Double
bool
Boolean
boolean
bool
bool
Boolean
char
Char
char
wchar_t
char
Char
string
String
string
String
string
String
object
Object
object
Object
object
Object

No comments:

Post a Comment