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.

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