As implied, a combination of rewarding good behavior and punishing bad behavior. Each child responds to different discipline differently. Also, keep the punishment/reward consistent. If you are out and your child acts out, take them out of the situation and address them the same way you would if you were home. If you hold back, because you are out in "public", they will catch on and push your limits to the point that you will not want to go out in "public".
My son can be spanked until you break your wrist and he will still pitch out. My kindergartner, however, will respond to just a change in the tone of my voice most times.
There are kids at the pool that we belong to that have no boundaries at all. It will get to a point where I am fearful of my kid getting hurt because of them and I will try (rather diplomatically) to correct their child. Most times, the parents are so clueless that their "angel child" is even doing anything wrong. Most times, I'll just say, "Let's not do this or that" so that my kid hears the same thing and even though he or she knows not to do it (and wasn't doing it themselves), they always hear consistent rules and boundaries.
Then again, I did have charges filed against me once for abuse on a female, so take what I say with a grain of salt.
I just try to remember, that parenting is just that. Raising a child. It's not a popularity contest.