What are some good ways to deal with this messy and unnecessary and not-really-dynamic generation of JavaScript:
var <%# JavascriptId %> = new BusinessChart(
'<%# JavascriptId %>',<%# CurrentUserId %>,'<%# ChartId %>'
,'<%# Helper.GetBaseUrl() %>','<%# ChartPath %>'
,'<%# Helper.ResolveUrl("~", true) %>'
);
<%# JavascriptId %>.Init();
I found this other question, but the answers don't seem to address the source of the smelliness.
I see a few specific issues:
- JavascriptId is a variable name. Why should I ever, EVER define a client-side variable name on the server side?
- The CurrentUserId doesn't ever change for the user... it's their user ID. Same for GetBaseUrl() and ResolveUrl("~")... Why should I pass constants all over the place?
- I have to open the aspx.cs codebehind file to debug stuff, and can't use Intellisense.
I have developed a couple ideas to deal with the above issues (declaring a global "Application" object, jQuery + declaring classes on DOM elements), but I'd like to hear more thoughts on this.
Thanks for any suggestions you might have.