Aspnot Posted April 25, 2005 Posted April 25, 2005 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 <asp:Label id="Label1" runat="Server>Some Text</asp:Label> Method 2 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!! Quote Aspnot
kahlua001 Posted April 25, 2005 Posted April 25, 2005 In this case, there seems no need to use a server control for displaying static text. Quote
Aspnot Posted April 25, 2005 Author Posted April 25, 2005 OK. Assume there was databinding involved. <%# DataBinder.Eval(Container, "DataItem.Abstract") %> Versus <asp:Label id="Abstract" runat="Server"><%# DataBinder.Eval(Container, "DataItem.Abstract") %></asp:Label> Quote Aspnot
kahlua001 Posted April 25, 2005 Posted April 25, 2005 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. Quote
HJB417 Posted April 26, 2005 Posted April 26, 2005 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.