Sometimes they are just 'feeling good' and act up and try to play, either way however good they are feeling they should not be stupid about it. When you're in the saddle they need to know that they need to behave.
If he acts up like that again, I would start by serpentining him down the wall, backing him up, doing tear drop turns etc...if he is still being stupid, it is okay to get off and lunge him if you work him harder on the line that when you are on him. Better to do that that put yourself in a situation you are not ready for.
If my mare is being stupid I work her harder. I am pretty comfortable up there so I wont get off, but if I wasn't I would get off put a long line on her and make her work hard, then when she calms down and slows down on the line I would ask her to stop and stand for awhile, then when she is standing and has reled I'd ask her to move forward slowly....if she does this and remains calm about it I'd ask her to stop again and I would go about remounting.
I have seen other horses have this done, in fact my boyfriend was taking lessons and an old hand decided she was feeling frisky and she tried to take off. Him being a novice rider was not comfortable giving her crap in the saddle, so the trainer got him off and put the mare on along line and made her canter around for a while...the horse tried to gallop or go uncontrolled and buck, she would push her harder. The mare realized that if she behaved she didn't have to work as hard and after that she was good. Differnet things work for different people put horses are by nature minimalists so when they're shown the best way to do the least amount of work they'll typically go that direction :p