 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

August 7th, 2010, 07:30 AM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
|
|
Naming Objects -Programming Etiquette
I'm cruising through chap. 5 programming, and concentrating on C# because it's my weaker language. Anyway, I am using labels and buttons to do the programs. It used to be you used btnSubmit for IDs or frmForm for your form. Is that old school now? (Note: Many times I don't rename Labels unless they used in my programming code) :-)
|
|

August 7th, 2010, 07:46 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
In forms, it's debatable. As I explain in the book, these prefixes are no longer needed for normal variables, like an integer or a string, IMO, this:
int age;
string firstName;
is easier to read (and maintain) than this:
int iAge;
string sFirstName;
Visual Studio provides IntelliSense for these variables and shows you their type so you don't need Hungarian notation anymore.
For form controls, it's still quite common to prefix a button with btn, a text box with txt and so on. However, I find myself leaving out these prefixes more and more. E.g.:
FirstName.Text = "Imar";
is, IMO, just as easy to read as:
txtFirstName.Text = "Imar";
Same goes for other controls. btnSubmit or SubmitButton are pretty much equivalent for me.
In other words: it mostly comes down to personal preference. Use what works best or feels most natural to you. My personal preference (which is what I used in the book) is to leave them out. It's difficult to learn an old dog new trigs so I still use them occasionally - as shown in the book with the cpMainContent placeholder as I found MainContentPlaceholder too long to write, and MainContent is already the name of a CSS class ;-)
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

August 7th, 2010, 02:32 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
|
|
Thanks Imar,
I am enjoying the programming chapter and have been mocking up pages with buttons and labels playing around with them.
I used this bit of code to determine my user.identity.name
Code:
protected void Button1_Click(object sender, EventArgs e)
{
if (!User.IsInRole("btcomp"))
{
DeleteButton.Visible = false;
}
string UserIdentityName = User.Identity.Name; // 'HOLLERITH/btcomp'
Label3.Text = UserIdentityName;
}
I was a bit confused with the User.IsInRole, and the User.Identity.Name returns the computer name and identity, though I only needed the identity to make the button invisible.
Anxious to get to Master pages as a possible client (job) keeps looking at my websites (mostly I have been using PHP and CSS) to see if I have done anything with ASP.NET and I think specifically with Master Pages.;-)
Last edited by btcomp; August 8th, 2010 at 01:43 PM..
|
|

August 7th, 2010, 05:18 PM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
|
|
Just to add to the section about naming conventions for forms I like to put in "btn", "txt" as this causes IntelliSense to pop up and then I have all my text fields, labels etc grouped together which is easier to manage if you are working with a large grouping of controls.
|
|

August 7th, 2010, 06:17 PM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
|
|
I like that idea Will, especially if you are using lots of the same object. I will keep that in mind. As it is I'm in the habit of putting txt and btn in front of said objects, but I may prefix when I am dealing with lots of the same.
|
|

August 8th, 2010, 03:47 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
I was a bit confused with the User.IsInRole, and the User.Identity.Name returns the computer name and identity, though I only needed the identity to make the button invisible.
|
The default authentication mechanism is Windows authentication, so you're logged in with the Windows account you use to start your browser.
In Chapter 16 you'll see how to change this.
Cheers,
Imar
|
|

August 8th, 2010, 07:42 AM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
|
|
Thanks Imar. I am just about done with chapter 5, lots of info in it and will refer back to it. Will be starting chapter 6 today. Breakfast now, 6 hours behind the Netherlands! In Michigan we have the city of Holland some 3 1/2 hours west of me on Lake Michigan, which is very beautiful, though I have never seen it during it's Tulip Festival.;-)
|
|

August 9th, 2010, 03:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
which is very beautiful, though I have never seen it during it's Tulip Festival.;-)
|
Too bad; sounds like something you cannot really miss ..... ;-)
Imar
|
|

August 9th, 2010, 07:08 AM
|
|
Authorized User
|
|
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
|
|
I know. We keep saying we will get there. We've been there other times of the year. I think I will make it a point to take my wife there, maybe next spring. ;-)
|
|
 |
|