I have inherited a large existing website to maintain. Previous developers have taken an erratic approach to project structure, and so one of the things I have been spending time working on is refactoring everything to make it more maintainable – for instance, gathering various copy-pasted blocks of html and code into usercontrols, setting everything up to derive from a master page, and generally spinning stuff off to live in libraries, rather than having functionality duplicated all over the place.
That was with the server side code. I now turn my focus to the client side functionality. The javascript at the moment is pretty bad. It suffers from a lot of the problems of the serverside code – there is a lot of duplicated functionality, unused functions, buggy functions, and so on, so I want to redo a lot of it. All the javascript code is stored in separate .js files. Often, it seems to duplicate functionality that could come from using asp.net controls instead, like the various validators.
I’ve not worked much with web techonologies before, but my instincts tell me that if I am going to be working with asp.net, I should be building my code with the tools provided by asp.net as much as possible. For instance, using stuff like RegisterClientScriptBlock to structure my code.
I previously asked a question related to this subject, but the responses I got were more about structuring javascript than about structuring an asp.net website.
What is the best, easiest to develop and most maintainable way to use javascript with an asp.net website?
RegisterClientScriptBlock is one the things you start trying in the first place and regret it soon. Javascript does not belong onto the server side. Totally not.
You really should use Separate Javascript files to wrap each control using the way microsoft creates their client side stuff. The problem is, even MSDN refers a lot to server-side code generation.
A good introduction about client side asp.net development can be found here: http://dotnetslackers.com/articles/ajax/ASPNETAJAXControlDevelopment.aspx