Ignore your dog's barking for as long as it takes him to stop.
That means don't give him any attention at all while he's barking.
When you put your dog in his crate or in a gated room, turn your back and ignore him.
Once he stops barking, turn around, praise him, and give him a treat.