Best to buy in advance if you can -- especially if you're after a sleeper train on that leg and are travelling in high season. Most just try heading down to the station a day or so beforehand and buy the ticket then -- as there are a few trains a day should be able to get something. If you but through a travel agent in Bangkok, expect a small surcharge.
If you know the day you're departing may as well buy the tickets in advance to save yourself the any possible hassle. The surcharge isn't that much and they can deliver the tickets directly to your hotel.
Note that the northern 1/3 of that line is currently closed for maintenance until at least November-1. They provide connecting bus service for that section, but it might not be so nice transferring to a bus at 2-5am as is the case with most sleeper trains.
Some agents surcharges can sometimes be between 200 - 300 baht. Make sure you know the real price of the ticket beforehand. I wouldn't call that a small surcharge! It was so much better when you could just book your ticket online via thairailticket.com
thanks everyone for the information. i'll be traveling that route after the closure (well, hopefully, you never know how long things will really take!) i understand thailrailticket.com no longer offers train tickets to buy but is thailandtrainticket.com a good source to buy from instead?