There are two approaches you can take to this very common problem.
Either will work. One is more work than the other. And some say that one is more gentle and humane than the other.
You must choose one technique and use it consistently.
(1) Use the knee
This is the one that even non-dog owners know about.
The dog comes up to you, quivering with excitement. He gets up to place his paws on his stomach or chest. You turn sideways just before he can put his paws on you, raising your knee so he meets a hard, pointy-but-blunt object. After hanging on to it for a second or two, he falls to the ground. You win.
There are a few extra things you can do at this point.
You can teach him that he gets a nice welcome when all four feet are on the ground by crouching next to him when he’s off your lap and giving him lots of attention and fuss.
And if he gets his paws on you before you can raise your knee, do your best to appear disinterested. Do not reward your dog in any way. (and that means don’t push him away with your hands, as this is an enjoyable game for any dog. Don’t talk to him. Ignore him. Do what he wants to be a game, a definite non-event.
OK. it’s the knee in the chest. But there is an alternative.
(2) Use your hands
When the dog jumps up, this second technique makes you grab his legs with both hands – and stand there. His jump has suddenly become “frozen”. Nothing happens. There was no reaction. Instead, he’s been caught and can’t do anything!
Keep him like this. Hold him and don’t move. Draw this out. Make it hang as long as you can. Talk to him if you want, but keep him up.
After a while, most dogs will start to chew on your hands. This is your signal — let him go. Hard. Do not lower him to the ground, but rather let him go abruptly.
Then, when he’s down on the ground, squat down with him and give him the encouraging, pleasant time he was hoping for by jumping up moments earlier.
In this way, he learns that the best reaction from you is always when he is on all fours!