What are the naming guidelines for ASP.NET controls?

后端 未结 18 1935
离开以前
离开以前 2020-12-07 21:23

We are in the process of nutting out the design guidelines we would like to use in our development team and got into a discussion today around how ASP.NET controls should be

18条回答
  •  执念已碎
    2020-12-07 21:45

    I've been struggling with this problem too. I used to use the "hungarian style prefix".

    Now I take a different approach, I try to see the controls as private fields from my class. I don't pre- of postfix my private fields with their type, so why should I do that to an TextBox?

    So what used to be:

    var newCustomer = new Customer();
    newCustomer.Name = txtName.Value;
    newCustomer.Address = txtAddress.Value;
    newCustomer.City = txtCity.Value;
    newCustomer.HasEnoughMoney = cbHasMoney.Selected;
    

    Becomes:

    var newCustomer = new Customer();
    newCustomer.Name = name.Value;
    newCustomer.Address = address.Value;
    newCustomer.City = city.Value;
    newCustomer.HasEnoughMoney = hasMoney.Selected;
    

    To be honest, I couldn't care less if the "name" control is a text box or what else, I just want it's value.

    And if it's not clear enough if your talking about your control or about another field/variable, I think you should either reconsider the name of that field/variable or the function of you class (meaning it might be a little bit to big?).

提交回复
热议问题