I think David said it best - you can't prevent hecklers, nor can you handle them with a specific magic trick.
For me, my thinking process is as follows:
1 - Don't look bothered, or let the heckler get to you. If the heckler sees that he's bothering you, that will just encourage him. If he's got to you, he's thrown you off your game; you may eventually shut him up, but he's won.
2 - Remind him that magic is a form of entertainment, and a demonstration of skill, not a puzzle to be openly discussed (don't obviously use that wording). Depending on the audience, I might just turn to the guy and say "I bet you were the one that went around telling everyone that Santa Claus wasn't real. Please, don't ruin it for those that still want to believe in magic." However, if I am feeling particularly nasty, I will just take out a modelling balloon and ask him to help me with the next trick by blowing it up. He won't be able to, but even if he does, it'll tire him out. So, either way, you just take back the balloon, blow it up to it's full length and make a balloon dog. Then just look at the heckler and say "Knowing how it's done is one thing. Being able to do it is another". However, be careful with this last one, as sometimes the fact that you openly ridiculed a heckler may lead the audience to sympathise with HIM and not you.
It is often said that the audience will tell the heckler to shut up, but I like to stop him early (when he's just a spoiler and long before he can become a nuisance). In short, it's a delicate balance between telling him to shut the **** up, and kindly be quiet.