Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!!

Aspnot
Posted

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>

Aspnot
Posted
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.
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...