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"></asp:Label>

//Tony
 
J

Jason Keats

Peter said:
No, not the same. The first label's text isn't capitalized.

I also don't know why you'd bother with an open/close tag for an
empty-content element. Why not just:

<asp:Label ID="suitLabel" runat="server" Text="Club" />

Oh, and you do know that there's an actual ASP.NET forum somewhere
around where questions like these are actually on-topic. Right?

I agree. I've never seen anyone use #2. That's just stupid.
 
J

Jason Keats

J.B. said:
You probably haven't done much ASP.Net then (either that or you do all
your coding using Notepad), because by default in the Visual Studio
IDE, if you type "<asp:Label", the moment you hit the ">" sign, the
closing tag is inserted for you. Same is true if you drag a label
from the toolbox onto the code window.

No one I know uses drag and drop in design view, so Text="Label" was
never an issue.
 
J

Jason Keats

J.B. said:
[...]
I also don't know why you'd bother with an open/close tag for an
empty-content element. Why not just:

<asp:Label ID="suitLabel" runat="server" Text="Club" />

I agree. I've never seen anyone use #2. That's just stupid.

You probably haven't done much ASP.Net then (either that or you do all
your coding using Notepad), because by default in the Visual Studio
IDE, if you type "<asp:Label", the moment you hit the ">" sign, the
closing tag is inserted for you. [...]

If you type a '/' before you type the '>', it won't add the closing tag.
Which is, of course, how one would type it in without the closing tag
anyway.

I don't see how it's an IDE problem.

I really wasn't implying it was a problem with the IDE, I just found
it difficult to believe that someone could do a significant amount of
work in ASP.Net with VS as the editor and never see an example like
the stated one. I've worked on a lot of different ASP.Net projects
since the release of .Net and I see that all the time -- I'd even say
its fairly common.

You're correct. Please excuse my hyperbole. Maybe I should have said:
"I've never seen anyone write #2." As you say, if you're using ASP.NET
WebForms (and especially if you're using drag and drop from the Toolbox)
then you're likely to see it a lot.

However, if you were sensible enough to bypass WebForms and use an MVC
framework - like Castle's Monorail - then you wouldn't have to put up
with such ugly HTML as you get to use NVelocity.

Alternatives are now everywhere. Have you tried OpenRasta and the Spark
view engine, for example?

Microsoft has seen the light, so now you also have ASP.NET MVC and the
Razor view engine to play with.
 

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

Top