How to Cast DotNet Labels as Text in VB?

I'm going crazy here trying to figure out how to send a label item from a dotnet form to email. I have no problems sending dropdownlist items or textbox items, but I can't seem to hit the syntax for a label.

The labels are displayed on my form based on the ID of the logged in user, in a DetailsView named LoggedInUser. Both of these statements display the Phone number:

<li>PHONE <font color="red"><%#Container.DataItem("PHONE")%></font> </li>
<li><asp:Label ID="LblPhone" runat="server"><%#Eval("PHONE")%></asp:Label> </li>

I've tried every variation of this statement that I can think of:

Dim phonenum = CType(LoggedInUser.FindControl("LblPhone"), Label).Text.ToString()

including Ctype, TryCast, DirectCast...and my resulting email is empty. So this iteration of my attempt doesn't throw an error, but doesn't produce a result either. Here's the line from my email formatting, if it helps:

sb2.AppendFormat(String.Format("<td bgcolor='#FFFFDD'>{0}", phonenum))

Who is Participating?
Paul JacksonConnect With a Mentor Software EngineerCommented:
Change your labels to use the Text property in the markup as shown below :

<asp:Label ID="LblPhone" runat="server" Text='<%#Eval("PHONE")%>'></asp:Label>
davewalter1Author Commented:
Beautiful! You are the man, Jacko. Thank you very much!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.