So my question is more in relation to what people consider to be the best practice and why:
I've been dropping literals into pages and repeaters and binding them in code behind for a while. Is this considered bad practice? ie:
ASPX Page:
<asp: Literal id="litTextToInsert" runat="Server" />
Code Behind:
litTextToInsert.Text = objData.MyText;
OR (repeater):
protected void rpt_ItemDataBoundVersion(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RepeaterItem objItem = e.Item;
Data.MyObject objDataItem = (Data.MyObject) objItem.DataItem;
Literal litMyText= (Literal)objItem.FindControl("litTextToInsert");
litMyText = objDataItem.MyText;
}
}
With most demos about MVC and general WebForms i see a lot of people simply dropping binding code into the front end
ie:
ASPX Page:
<%#Eval("MyText") %>
I personally dont like doing this as i find it makes it harder for me to know if someone changed the field name, or mis typed it during development - the other way you won't know until the page loads.
With the strongly typed version if something changes in your DAL etc the build will break - letting me know I've messed up.
Why do so many people appear to use weakly typed code in ASP.Net (in examples, MVC, etc)? Am i missing something? Am i an idiot and missing the point? Is this just because its demo code attempting to be simpler?
Let me know.