<p>If I use the following code I lose the ability to right click on variables in the code behind and refactor (rename in this case) them</p>

<pre><code>&lt;a href='&lt;%# "/Admin/Content/EditResource.aspx?ResourceId=" + Eval("Id").ToString() %&gt;'&gt;Edit&lt;/a&gt;
</code></pre>

<p>I see this practice everywhere but it seems weird to me as I no longer am able to get compile time errors if I change the property name.
My preferred approach is to do something like this</p>

<pre><code>&lt;a runat="server" id="MyLink"&gt;Edit&lt;/a&gt;
</code></pre>

<p>and then in the code behind</p>

<pre><code>MyLink.Href= "/Admin/Content/EditResource.aspx?ResourceId=" + myObject.Id;
</code></pre>

<p>I'm really interested to hear if people think the above approach is better since that's what I always see on popular coding sites and blogs (e.g. Scott Guthrie) and it's smaller code, but I tend to use ASP.NET because it is compiled and prefer to know if something is broken at compile time, not run time.</p>

[{'answer_id': 68530, 'author': 'Kilhoffer', 'author_id': 5469, 'author_profile': 'https://Stackoverflow.com/users/5469', 'pm_score': 3, 'selected': True, 'text': "<p>I wouldnt call it bad practice (some would disagree, but why did they give us that option in the first place?), but I would say that you'll improve overall readability and maintainability if you do not submit to this practice. You already conveyed out a good point, and that is IDE feature limitation (i.e., design time inspection, compile time warning, etc.).</p>\n\n<p>I could go on and on about how many principles it violates (code reuse, separation of concerns, etc.), but I can think of many applications out there that break nearly every principle, but still work after several years. I for one, prefer to make my code as modular and maintainable as possible.</p>\n"}, {'answer_id': 68533, 'author': 'Jiaaro', 'author_id': 2908, 'author_profile': 'https://Stackoverflow.com/users/2908', 'pm_score': 1, 'selected': False, 'text': "<p>It's known as spaghetti code and many programmers find it objectionable... then again, if you and the other developers at your company find it readable and maintainable, who am I to tell you what to do.</p>\n\n<p>For sure though, use includes to reduce redundancy (DRY - don't repeat yourself)</p>\n"}, {'answer_id': 68552, 'author': 'Brent', 'author_id': 10680, 'author_profile': 'https://Stackoverflow.com/users/10680', 'pm_score': 0, 'selected': False, 'text': '<p>It\'s up to you. Sometimes "spagehetti" code is easier to maintain than building/using a full on templating system for something simple, but once you get fairly complicated pages, or more specifically, once you start including a lot of logic into the page itself, it can get dirty really quickly. </p>\n'}, {'answer_id': 68830, 'author': 'Jack B Nimble', 'author_id': 3800, 'author_profile': 'https://Stackoverflow.com/users/3800', 'pm_score': 0, 'selected': False, 'text': '<p>I think it is interesting that more asp.net is requiring code in the aspx pages. The listview in 3.5, and even the ASP.NET MVC. The MVC has basically no code behind, but code in the pages to render information.</p>\n'}, {'answer_id': 68868, 'author': 'Alan Harris', 'author_id': 10847, 'author_profile': 'https://Stackoverflow.com/users/10847', 'pm_score': 1, 'selected': False, 'text': "<p>I use it only occasionally, and generally for some particular reason. I will always be a happier developer with my code separated entirely from my HTML markup. It's somewhat a personal preference, but I would say this is a better practice.</p>\n"}, {'answer_id': 68924, 'author': 'neouser99', 'author_id': 10669, 'author_profile': 'https://Stackoverflow.com/users/10669', 'pm_score': 0, 'selected': False, 'text': "<p>If you think of it in terms of template development, then it is wise to keep it in the view, and not in the code behind. What if if needs to change from a anchor to a list item with unobtrusive JS to handle a click? Yes, this is not the best example, rather just that, and example.</p>\n\n<p>I always try to think in terms of if I had a designer (HTML, CSS, anything), what would I have him doing and what would I be doing in the code behind, and how do we not step on each other's toes.</p>\n"}, {'answer_id': 68943, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 0, 'selected': False, 'text': "<p>Its only a bad practice, if you cannot encapsulate it well.</p>\n\n<p>Like everything else, you can create nasty, unreadable spaghetti code, except now you have tags to content with, which by design aren't the most readable things in the world.</p>\n\n<p>I try and keep tons of if's out of hte template, but excessive encapsulation, leads to having to look in 13 diferent places to see why div x isn't firing to the client, so its a trade off.</p>\n"}, {'answer_id': 68992, 'author': 'Graviton', 'author_id': 3834, 'author_profile': 'https://Stackoverflow.com/users/3834', 'pm_score': 0, 'selected': False, 'text': "<p>It's not, but sometimes it's a necessary evil.</p>\n\n<p>Take your case for an example, although code behind seems to have a better separation of concern, but the problem with it is that it may not separate out the concerns as clearly as you wish. Usually when we do the code behind stuff we are not building the apps in MVC framework. The code behind code is also not easy to maintain and test anyway, at least when compare to MVC.</p>\n\n<p>If you are building ASP.NET MVC apps then I think you are surely stuck with inline code. But building in MVC pattern is the best way to go about in terms of maintainability and testability.</p>\n\n<p>To sum: inline code is not a good practice, but it's a necessary evil. </p>\n\n<p>My 2cents.</p>\n"}, {'answer_id': 70100, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Normally I use like this way.</p>\n\n<pre><code>&lt;a href=\'&lt;%# DataBinder.Eval(Container.DataItem,"Id",""/Admin/Content/EditResource.aspx?ResourceId={0}") %\'&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/68509', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6084/']