Wrox Programmer Forums
|
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
 
Old August 7th, 2010, 07:30 AM
Authorized User
 
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default 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) :-)
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
 
Old August 7th, 2010, 07:46 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
btcomp (August 7th, 2010)
 
Old August 7th, 2010, 02:32 PM
Authorized User
 
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

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.;-)
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill

Last edited by btcomp; August 8th, 2010 at 01:43 PM..
 
Old August 7th, 2010, 05:18 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

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.
__________________
Follow me on twitter.

Where I work.

Connect with me on LinkedIn

Blog
 
Old August 7th, 2010, 06:17 PM
Authorized User
 
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

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.
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
 
Old August 8th, 2010, 03:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 8th, 2010, 07:42 AM
Authorized User
 
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

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.;-)
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill
 
Old August 9th, 2010, 03:19 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 9th, 2010, 07:08 AM
Authorized User
 
Join Date: Jul 2010
Posts: 81
Thanks: 10
Thanked 3 Times in 2 Posts
Default

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. ;-)
__________________
Bob
bdtcomp.com
http://lettersfromasoldier.com
Follow me on Twitter
“Success is not final, failure is not fatal: it is the courage to continue that counts.”~Winston Churchill





Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming Confliction harjinder645 BOOK: Beginning T-SQL with Microsoft SQL Server 2005 and 2008 ISBN: 978-0-470-25703-6 0 July 5th, 2010 12:58 PM
Variables in the four naming conventions FJInfante SQL Server 2000 3 May 1st, 2006 01:06 PM
Naming a new table SKE Classic ASP Databases 2 March 23rd, 2005 03:25 PM
Stored Procedure Naming jmurdock BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 July 2nd, 2004 10:22 AM
Naming conventions jara VS.NET 2002/2003 3 June 22nd, 2003 04:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.