This is a common frustration for even the most experienced of skiers.
I have found that the most common problem is weight distribution. Most people tend to lean on their back foot a bit too much when they start hitting rails. This almost always leads to slippage and a crash.
So keep in mind, weight your feet evenly. Your downhill foot should have just as much weight on it as the trailing foot. This will make sliding sideways much more predictable.