A web server label control

T

Tony Johansson

Hello!

I just wonder why some example use the label control in this way as #1.
I find it more sensible to use the label control as in example #2.
Is it the same if the label is used as #1 and #2 ?

#1 <asp:Label ID="suitLabel" runat="server">club</asp:Label>
#2 <asp:Label ID="suitLabel" runat="server" Text="club" />

//Tony
 
B

Brian Cryer

Tony Johansson said:
Hello!

I just wonder why some example use the label control in this way as #1.
I find it more sensible to use the label control as in example #2.
Is it the same if the label is used as #1 and #2 ?

#1 <asp:Label ID="suitLabel" runat="server">club</asp:Label>
#2 <asp:Label ID="suitLabel" runat="server" Text="club" />

They are almost equivalent but not quite.

In the first example <asp:Label ID="suitLabel"
runat="server">club</asp:Label> the value of suitLabel.Text is empty even
though it renders as "club".

In the second example <asp:Label ID="suitLabel" runat="server" Text="club"
/> the value of suitLabel.text is "club" and it renders as "club".

So I would suggest always going for the second method as that way you will
see the text listed in the label properties in Visual Studio.

Hope this helps.
 
T

Tony Johansson

Brian Cryer said:
They are almost equivalent but not quite.

In the first example <asp:Label ID="suitLabel"
runat="server">club</asp:Label> the value of suitLabel.Text is empty even
though it renders as "club".

In the second example <asp:Label ID="suitLabel" runat="server" Text="club"
/> the value of suitLabel.text is "club" and it renders as "club".

So I would suggest always going for the second method as that way you will
see the text listed in the label properties in Visual Studio.

Hope this helps.
Test
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top