asp.net - Is inline code in your aspx pages a good practice? -


if use following code lose ability right click on variables in code behind , refactor (rename in case) them

<a href='<%# "/admin/content/editresource.aspx?resourceid=" + eval("id").tostring() %>'>edit</a> 

i see practice everywhere seems weird me no longer able compile time errors if change property name. preferred approach this

<a runat="server" id="mylink">edit</a> 

and in code behind

mylink.href= "/admin/content/editresource.aspx?resourceid=" + myobject.id; 

i'm interested hear if people think above approach better since that's see on popular coding sites , blogs (e.g. scott guthrie) , it's smaller code, tend use asp.net because compiled , prefer know if broken @ compile time, not run time.

i wouldnt call bad practice (some disagree, why did give option in first place?), you'll improve overall readability , maintainability if not submit practice. conveyed out point, , ide feature limitation (i.e., design time inspection, compile time warning, etc.).

i go on , on how many principles violates (code reuse, separation of concerns, etc.), can think of many applications out there break every principle, still work after several years. one, prefer make code modular , maintainable possible.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -