A web server label control

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
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
 
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.
 
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
 
Back
Top