let's say I want to display my "Person" class.
I can do it in two ways:
put a few asp:labels in my html, and fill them in my server code:
lblName.Text = person1.Name lblAge.Text = person1.Ageuse the asp:formView control, so my server code will look like this:
Dim myDataSource = New Object() {person1} FormView1.DataSource = myDataSource FormView1.DataBind()and my html will look like this:
<asp:FormView ID="FormView1" runat="server"> <ItemTemplate> Name:<%# Eval("Name")%> <br /> Age:<%# Eval("Age")%> </ItemTemplate> </asp:FormView>
which way is better? what is the cost of using the server tags?
It is the same because the controls have to be
runat="server"and it assign the values to the control from server side.The main difference is that you assign the values in code_behind file or in markup file. Wherever you prefer. In both cases it will need to go server side to gather that values.
I don't think the cost of using server tags would be different to assign values in code file, because they are processed in page's render phase.
Extrated from msdn: