When I arrived at my current role, the first and most obvious problem that made maintenance next to impossible was the intertwining of javascript with the C# code behind. It was one of my pet peeves before I arrived to see C# strings used to inject javascript into a page but the codebase here was almost unbelievable - javascript that called a setTimeout with javascript inside it that had multi-escaped double quotes inside the string.
Now, sometimes there's just no avoiding it - if you want to get that truely fantastic maps integration to work really slickly with the data in your working context you might have to inject some dynmically generated javascript. Now, most of the time it would be better to do it by using json, parameterising properly but sometimes it's difficult to avoid. The prime example would be when you're trying to write a server control that outputs javascript appropriate to its environment based on some control parameters.
So, how do we solve the problem? Well, javascript lives in javascript files for a reason. Code seperation is there for a reason too but there just wasn't a mechanism for creating the kind of dynamic javascript we wanted. The solution I came up with was to have the server read in from a series of javascript file resources that contained some placeholder symbols to put variables in to. I did the same for HTML injection where we needed to dynamically output html, which was also pretty useful.
Of course, since we finally managed to convince the boss that jQuery was a good thing the need for all of that has dropped significantly but it's still a nice thing to be able to do. I'll post a link to the javascript reader class and html reader class soon so that anyone that wants to can use it.
A technical blog from an ASP.NET / C# developer about anything I find interesting or useful.
Friday, 24 June 2011
Making more of this blog
Well, the decision is made and it's coming up to crunch time. I've been working my way up to becoming a contractor for a long time and now I've got a fixed time frame to do it. Come mid-August the notice is going in and I'll be looking for a contract as soon as I can get one. So I've decided to put more posts out on this blog to give myself a bit more of a proffessional presence on the internet. I'll look at migrating any posts I make out to my own website as soon if I ever get the time (I imagine that will be priority one if I find myself in need of a project to do whie I'm looking for work - if I get work straight away though then I won't have such a need for the blog ;-) ). Anyway, I hope the stuff I put out there is useful to somebody
Subscribe to:
Posts (Atom)