ASP.NET Label Control vs Literal Control

7. August 2012 12:21 by Forrest C. Shields II in .NET  //  Tags: ,   //   Comments (0)

Difference between Label and Literal controls

The Literal control reserves a spot in your HTML page for content that is directly injected into the page without adding any additional tags. It is more basic (and lightweight) than the Label control. The Label control has more formatting options and can tie your label to an HTML input control.

The ASP.NET Label control

Inheritance Hierarchy:

Because it inherits from WebControl, you have lots of styling/theming options.

Contrary to popular belief, the Label control can be used to inject HTML into the page. From Microsoft's documentation: "The Text property can include HTML. If it does, the HTML will be passed unchanged to the browser, where is might be interpreted as markup and not as text."

Normally, it wraps the entire output in <span> tags.

You can associate it with another control using the AssociatedControlID property. When you do this, the output is wrapped in <label> tags instead of <span> tags. This ties your your label correctly to your input control:

<asp:Label id="Label1" AssociatedControlId="TextBox1" Text="First Name:" runat="server" />
<asp:TextBox id="TextBox1" runat="server" />

Yields the following HTML:

<label for="TextBox1" id="Label1">First Name:</label> 
<input name="TextBox1" type="text" id="TextBox1" />

The ASP.NET Literal control

Inheritance Hierarchy:

Inject pre-formed HTML into your page using Mode="PassThrough":

<asp:Literal ID="TestLiteral" runat="server" Mode="PassThrough"
             Text="This is <b>bold</b>"></asp:Literal>

Yields: This is bold

Or have it automatically HTMLEncode your text using Mode="Encode":

<asp:Literal ID="TestLiteral" runat="server" Mode="Encode"
             Text="This is <b>bold</b>"></asp:Literal>

Yields: This is <b>bold</b>

The Literal control does not add any extraneous HTML, unlike the Label control.


For the most part, the Literal control is just a placeholder for content. (In fact, I wish they had just called it the Content control!) You should use it in most cases, unless you need the styling/theming capability of the Label control or if you are actually labeling an input control. Never use a Label control when a Literal will do.

UPS My Choice: No Thanks!

2. August 2012 12:48 by Forrest C. Shields II in Reviews  //  Tags: , , ,   //   Comments (1)

UPS My Choice...Paying for UPS's Convenience

I know. This is a technology blog. So how does a shipping company fit here. Well, I know it is stretching it a bit but I have quite a few electronic items shipped to me on a regular basis. The real truth is that I just had to comment on it and this is my only blog.

UPS currently has an advertising campaign pushing their free "My Choice" program. While it has some nice features such as advance delivery notifications via e-mail or text message (but not both!?!?), I was really interested in the capability to delay delivery of my packages if I was on vacation.

Once you are signed up, you can go to the UPS My Choice Vacation Settings page. You are given the following notice:

For vacations lasting up to 14 days, you can reschedule your deliveries for a later date.
For vacations lasting up to 7 days, you can either reschedule your deliveries for a later date, or deliver your shipments to a UPS Retail Location (e.g., The UPS Store).
Note: A transaction fee will be charged for each package delivered during your vacation period.

Wait a minute... "A transaction fee"? What's that? Why won't they tell me what the fee is?

There is no further help on the page. So after a little digging in other areas of their site, I come to discover that I will need to pay $5.00, per package, to have them delay delivery!  So now I see why they didn't put the rate on the page...they are embarrassed about how much they are asking.

Why does this cost so much? Well, I'll tell you why it shouldn't:

  1. I'm saving the UPS driver 3 delivery attempts by letting them know I'm on vacation.
  2. I'm saving UPS the cost of sending the package(s) back to sender if I'm not there for 3 days.
  3. A per-package fee!  Come on! The work the driver has to do is the same for 3 packages as it is for 1.
  4. All of this happens in the sorting centers, not on the truck anyway.
  5. Storing it at a UPS Store is practically a no-cost situation for you because they are the last stop for the delivery trucks at the end of the day, and they'd have to store the package for free for 3 days anyway during your redelivery attempts.

Quite honestly, I think that that this service should be free since it mostly benefits UPS. However, I'd be willing to pay up to $2 per vacation period for the feature since I also get some benefit. However, this just looks like another attempt to nickle-and-dime me out of my money. What could have been a marketing coup for UPS (if done correctly) has turned into a negative.

I've been a big fan of UPS in the past, but this is very disappointing.

Resolving Reverse DNS Lookups in PowerShell (and some issues to be aware of)

1. August 2012 20:59 by Forrest C. Shields II in PowerShell  //  Tags:   //   Comments (6)

Reverse DNS Lookups

God, I love PowerShell! What do you do when you want to find out the host name associated with an an IP address, such as  Well you can do this:


But GetHostByAddress is Obsolete

According to the MSDN documentation for the .NET Framework 4, the GetHostByAddress() method is "obsolete". This isn't a problem for PowerShell v1 and v2 users because each of those use .NET 2.0.  However, if you want your scripts to be forwardly compatible with Powershell v3 (which uses .NET 4.0), then you will have to find another method.  Thankfully, there is a recommended replacement method called GetHostEntry() that has been in place since .NET 2.0 so it will work now and in the future.


Problems Galore with GetHostEntry()

Problem #1

I swear that I thought I must be going crazy, or that there is a bug in one of the System.Net.Dns methods!  The results from GetHostEntry() are not the same as from GetHostByAddress().

Try this using the old method:

PS C:\Users\fshields> [System.Net.Dns]::GetHostByAddress("")

HostName                                Aliases               AddressList
--------                                -------               -----------         {}                    {}

Now try the new method:

PS C:\Users\fshields> [System.Net.Dns]::GetHostEntry("")
Exception calling "GetHostEntry" with "1" argument(s): "No such host is known"
At line:1 char:31
+ [System.Net.Dns]::GetHostEntry <<<< ("")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

No, you didn't make a typing mistake. The same IP address resolved in one case and not in another.

GetHostEntry() is overloaded for both a String input and a IPAddress input. So I thought that I'd specifically cast my address as an IPAddress just to ensure that this wasn't the problem:

PS C:\Users\fshields> [System.Net.Dns]::GetHostEntry([System.Net.IPAddress]"")
Exception calling "GetHostEntry" with "1" argument(s): "No such host is known"
At line:1 char:31
+ [System.Net.Dns]::GetHostEntry <<<< ([System.Net.IPAddress]"")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

The strange part is that this only happens with certain IP addresses such as or Most other IP addresses resolve fine.

Upon further investigation of the MSDN documentation, I discover that the GetHostEntry() method first does a reverse lookup on the IP address to find a host name (from the DNS PTR record), then it does a forward lookup on that host name (from the host name's DNS A record) to populate the AddressList property. However, if the forward lookup fails (due to lack of a DNS A record) then the method bombs out with an Exception and doesn't return an object!

I can't go into all the reasons why this is complete bogus, but suffice it to say that there are legitimate reasons why a DNS PTR record would not have a corresponding A record. In fact, this is rather common on the Internet.

Problem #2

If the IP address you are using is a non-routable one (one of the private IP addresses:,, or then thow out everything I just said above. For some reason, it returns the IP address as the HostName:

PS C:\Users\fshields> [System.Net.Dns]::GetHostEntry("")

HostName                                Aliases               AddressList
--------                                -------               -----------                             {}                    {}

Problem #3

If you pass it an empty String, it will return the NETBIOS name of the local computer!

PS C:\Users\fshields> [System.Net.Dns]::GetHostEntry("")

HostName                                Aliases               AddressList
--------                                -------               -----------
MyPC                                    {}                    {}

While this may seem to be a convenient way to get the host name, it really sucks if you are processing a list of IP addresses and some of them are blank.


What to do? Really, you have no choice but to use the soon-to-be "obsolete" GetHostByAddress(). Sorry.

Which is Better for Kids: Arduino or Raspberry Pi

18. July 2012 13:05 by Forrest C. Shields II in Arduino, Raspberry Pi  //  Tags: , , , ,   //   Comments (0)

Which platform, Arduino or Raspberry Pi, should you choose for your child to learn programming?

I recently received an e-mail from a mother who was wondering which device would be better for her daughter to learn programming on, the Arduino or the Raspberry Pi.  Some of the answer is predicated on what you want your child to learn.

The Arduino is a microcontroller with a very small amount of memory and no display device.  It interfaces with electronic components very well and has a great support community. This device would certainly teach computers and programming at a very low level, which will serve them well in understanding future computing concepts.  However, it is more difficult to use without an understanding of electronics and might be frustrating to children who want immediate feedback.

The Raspberry Pi is a full-blown computer that runs Linux. It can be plugged into an HDTV set, can interface with USB peripherals such as keyboard, mouse, webcam, printer, etc.  It also has built-in Ethernet networking for accessing the Internet. The programming experience on this device will be closer to a traditional programming course. The level of understanding of computer hardware will be diminished, but feedback will be more immediate and a much larger variety of programs can be made.

Here is list of features for contrast:



  • Cheap (~$25).  Available at Radio Shack for $35
  • Huge support community
  • A fantastic way to learn how computers really work
  • You will learn to write tight code


  • Limited to one programming language ("Processing", which is like C)
  • No native display capabilities
  • To get beyond programs that just blink an LED, you need to start learning about electronics, hardware, soldering, etc. which may be beyond younger learners
  • Requires another computer for programming. The Arduino is then connected to the computer and the code is loaded onto it.

Raspberry Pi


  • Cheap ($35)
  • Multiple programming languages: Python (the preferred language), Scratch (a visual language designed for kids), and of course C++
  • Linux — You have access to all that Linux offers, including tens of thousands of pre-written programming libraries
  • The display capabilities give you much greater options. This alone might help to keep your child interested since they can program things like games (see PiSnake).
  • Built-in Ethernet networking and USB support


  • Integration with electronics is possible, but poorly documented
  • The support community is still very new, but it is growing rapidly
  • Linux — In order to function in the RPi environment, you'll have to learn Linux and the commandline.  Not a bad secondary learning experience, but it makes startup slower.

Introducing the Raspberry Pi

3. July 2012 19:00 by Forrest C. Shields II in Embedded Systems, Raspberry Pi, Reviews  //  Tags: ,   //   Comments (0)

What is the Raspberry Pi?

It is a full-blown Linux computer with HDMI (1080p) output, USB ports, and General Purpose IO (GPIO) pins for expanadability... all for ony US$35!

Below you will find a link to the presentation that I gave on July 3rd to the Colorado Springs Embedded Systems Group:

     Raspberry Pi - ColoSpgs Embedded Systems Group.pdf (1.09 mb)

This was just a cursory introduction to the Raspberry Pi.  There will hopefully be more posts as I have time to play with my new board.

If you are interested in learning more about the Raspberry Pi, here is a list of the most useful resources:

Please give me feedback on your Raspberry Pi experiences.

Welcome to my Blog!

17. April 2012 22:54 by Forrest C. Shields II in   //  Tags:   //   Comments (0)

Welcome to my new blog. I'm excited to begin and have several ideas in mind. I just hope that I don't run out of energy/ideas/time like so many other bloggers do.

What you can expect

You can expect the unexpected! My blog is titled "Technologica Eclectica" for a reason. This blog will be my stream-of-conciousness on an ecelectic mix of all things technology related. It will actually be a close reflection of my varied interests, experience, and competencies.

Please participate

I really want this to be an interactive dialog. To that end, I've enabled comments. Please participate in the conversation.


Forrest C. Shields II

About the author

Forrest C. Shields II is a Technology Consultant at, LLC in Colorado Springs, CO USA. Forrest has worked as a consultant for over 22 years where he specializes in using technology to find solutions to business problems in the small-to-medium sized business sector. His expertise covers the entire spectrum of Microsoft products, including: SharePoint, Exchange, SQL Server, IIS, Hyper-V, and the entire Microsoft Office Suite.

Month List