No offence intended to the quoted author here, but does anybody
actually write code that looks like this? The code below is
functionally equivilant, yet is readable as HTML:
Well, for this situation, the question/sample was requested for a LinkButton.
There are times when the question asked is along the wrong path and thus
sometimes need readjusting. But then other times, for the sake of simplicity,
it is easier to accept the flawled lead and just answer the question to get
the dev up and running.
I cannot understand why anbody would choose to use <asp:LinkButton>
over <a>, <asp:TextBox> over <input type=text>, <asp:label> over
<span>, etc. Every HTML tag is capable of taking a runat=server
attribure and exposing its DOM properties to the server. Why then,
would we use Microsoft proprietary equivilants for these things, when
we get little or no added functionality from them?
There are times, though, when it is preferable to use a server side object
to do interesting work. Now of course, there are usually two choices between
HtmlControls and WebControls. WebControls, in my experience, tend to provide
a richer and more consistent API. Also, WebControls fire server side event
by default, so if I require a server event then these controls will be my
preference. When I am not interested in taking over tight control over the
client rendering/behavior, I go with WebControl. This is the majority of
the time I use server-side controls. The only time I choose HtmlControls
is when I need a server side object to initialize some data on the control
and I want control of the client side tag (with script typically) but then
from then on the control/tag will be client side only, meaning no postbacks.
Could it possibly be for cross-platform compatability? Is there
actually a case where <asp:LinkButton...> will render anything other
than <a href=...>? Somehow I doubt it.
But as you've noted, at the end of the day, these things need to render as
good old HTML. For a simple control, you're right, there's little cross browser
compatibility. For other controls there is some merit to that argument. I
imagine you're aware of those other controls (and benefits).
The only explaination I can come up with is that since the Drag & Drop
designer uses the <asp:...> tags, developers just assume that they
cannot use HTML in their ASPXs anymore. Laziness and undereducation?
This hardly sounds possible in all cases.
So I don't follow what you're getting at? Why does it matter which control
you use? We've agreed that they both render as HTML. Why is it such an issue?
Each provides its own pros and cons based upon the situation upon which it's
being used and what the dev's trying to accomplish. As I mentioned above,
I prefer to use WebControls as they facilitate and ease my development (in
general).