title: Rendering javascript at the server side level. A good or bad idea?
body: <p><em>Now a community wiki!</em></p>
  
  <p><strong>I want to make it clear first</strong>: This isn't a question in relation to server-side Javascript or running Javascript server side. This is a question regarding rendering of Javascript code (which will be executed on the client-side) from server-side code.</p>
  
  <p>Having said that, take a look at below ASP.net code for example:</p>
  
  <pre><code>hlRemoveCategory.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this?');")
  </code></pre>
  
  <p>This is prescribing the client-side <code>onclick</code> event on the server-side.</p>
  
  <p>As oppose to writing Javascript on the client-side:</p>
  
  <pre><code>$('a[rel=remove]').bind('click', function(event) {
      return confirm('Are you sure you want to delete this?');
  }
  </code></pre>
  
  <p>Now <strong>the question I want to ask is</strong>: <em>What is the benefit of rendering javascript from the server-side code? Or the vice-versa?</em></p>
  
  <p>I personally prefer the <strong>second way</strong> of hooking up client-side UI/behaviour to HTML elements for the following reasons:</p>
  
  <ul>
  <li>Server-side does what ever it needs to already, including data-validation, event delegation and etc; and</li>
  <li>What server-side sees as an event is not necessarily the same process on the client-side. i.e., there are plenty more events on client-side (just look at custom events); and</li>
  <li>What happens on client-side and on server-side, during an event, <em>could be</em> completely irrelevant and decoupled; and</li>
  <li>What ever happens on client-side happens on client-side, there is no <em>need</em> for the server to know. Server should process and run what is given to them, how the process comes to life is not really up to them to decide in the event of the client-side events; and so on and so forth.</li>
  </ul>
  
  <p><strong>These are my thoughts obviously</strong>. I want to know what others think and if there has been any discussions on this topic.</p>
  
  <p>Topics branching from this argument can reach:</p>
  
  <ul>
  <li>Code management: is it easier to render everything from server-side?</li>
  <li>Separation of concern: is it easier if client-side logic is separated to server-side logic?</li>
  <li>Efficiency: which is more efficient both in terms of coding and running?</li>
  </ul>
  
  <p><strong>At the end of the day</strong>, I am trying to move my team to go towards the second approach. There are lot of old guys in this team who are afraid of this change. I just wish to convince them with the right facts and stats.</p>
  
  <p>Let me know your thoughts.</p>
  
  <p><strong>UPDATE1:</strong> It looks like all of us who have participated in this post have common thought; Good to know that there are others who think alike. Now to go convince the guys ;) Thanks everyone.</p>