This would depend on your local laws and details about the contract. And of course other details about your relation to this customer.
If I understand this right, your contract was about client side code (was this mentioned in the contract?)
I have seen such customers before and since you don't want to do any business with them ever again, because this types will act like this again, you can simply tell them that they either pay or hear from your lawyer. Sometimes this works (I know of cases where it did). If it's actually worth the effort to have a lawyer handle this may depend on too many details. Here in Germany this mostly has a very positive effect on the customers decisions regarding payment.
Edit
Ok, this above was mainly in case you have no close relations to the customer and have given up on him more or less anyway.
Of course having a clear contract that describes the kind of work and payment to be received as exact as possible is something you should have. This is, as you say, not always possible for many reasons. So, if you can't have a firm contract, you must act firm. As David says, otherwise they won't respect you.
You can stay friendly and at the same time make your point, that you can't be expected to work for free.
Real world example (names changed of course)
Some unimportant meeting with customers project manager about the actual state of the project (refactoring a large website from another company they had messed up full scale, lots of debug work).
She (project manager): Oh, and do you think it is possible to add a CMS for those sites.
Me: Sure, we could add an editor in the admin interface and move the text into the database, maybe add some option to upload images and so on.
Three weeks later, meeting at customers office, discussion about state of project (online by now, no bugs, customers of customer very happy) and next steps:
She: Oh, and didn't you want to add a CMS?
Me (hard time not to laugh): Look Claire, we talked about if it is possible to add this feature. If whenever we talk about something being possible and I say that it is, that means I agree to do it without payment, then in future talking will become very, very complicated, because we will need to add a lot of extra clauses to every single sentence.
This made that point quite clear without becoming unfriendly. You have to go through such situations once in a while and learn how to handle them. You must understand, that often enough this is like a chess game for some people, they make their move to get a bit more. Especially if it's the manager type. If you counter that move they mostly don't try again. Those guys are not necessarily serious about this stuff, they often know well enough that they are in a weak position. They only try, because sometimes it works.