title: MVC, ascx and Javascript best practice(s) - how to create self-containing controls? NerdDinner does it wrong
body: <p>The question is how to create controls/partial views/edittemplates (ascx files) in ASP.Net MVC2 so that they are "self-containing". Self-containing means here that if some Javascript code should be applied on the control, that's not included in the page (aspx), but in the control itself.
  Specific example:
  NerdDinner's DateTime.ascx. The file contains the JS code which makes the textbox a nice DateTime picker.</p>
  
  <p>My problems:
  The containing page has the jQuery.js, the timepicker.js, the jQueryUI's css and the datepicker's css. (In case of NerdDinner these all are in the master page). So whenever I'd like to use the fancy DateTimePicker for my DateTime types, <strong>the containing page has to be aware of these dependencies</strong> and has to add all the js and css files. I think what I miss here is a solution which replaces the ClientScript.RegisterClientScriptBlock.</p>
  
  <p>Other problem with the same NerdDinner example:
  In the DateTime.ascx it says $('#Dinner_EventDate') which is a dependency both on the container type and on the property name. That's not a general solution for a DateTime shared EditorTemplate.</p>
  
  <p>Any suggestions?</p>