Purist: To be or not to be

Aspnot

Freshman
Joined
Feb 24, 2004
Messages
37
I am unsure of whether there is any benefit to coding one way versus another, so I thought this would be a good place to ask my question.

Is there any benefit or advantage to Method 1 vs. Method 2?

Method 1
Code:
<asp:Label id="Label1" runat="Server>Some Text</asp:Label>

Method 2
Code:
Some Text

I know the purist tells me to use Method 1, but that's a lot more code to sort through than Method 2.

It would appear to me that all the <ASP:> tags are doing is getting interpreted by the server and that would lead me to believe there is more overhead involved with this method...

Thoughts, suggestions, preferences?

Thanks in Advance!!
 
OK. Assume there was databinding involved.

Code:
<%# DataBinder.Eval(Container, "DataItem.Abstract") %>

Versus

Code:
<asp:Label id="Abstract" runat="Server"><%# DataBinder.Eval(Container, "DataItem.Abstract") %></asp:Label>
 
Of your two examples, I would use the first one since you are correct, there is overhead to creating a server control. However, i would prefer setting the label's text in code behind and provide that extra layer to 'abstract' your business layer and in this case, your data field name. But getting back to the given examples, if you care about encapsulating the text into an object that has properties you can call like Color, Visiblity, Size in one line, then I'd use the Label.
 
there's still no need to make it a server control. =D
Generally, you only need to make it a server control if you need access to the element in your .net code or in a post-backed environment.
 
Back
Top