Gaining weight is not always a bad thing. When you exercise, you may be loosing fat tissue which was the plan to begin with, but you will also be gaining muscle tissue. With this being said, the more muscle you gain, the more weight you will gain, why? Simply because muscle tissue weighs more than fat tissue. That is probably the reason why you keep gaining weight when you exercise. Like I said, gaining weight is not always a bad thin. :)
If you lift heavy you will gain weight, if your running and doing a lot of cardio then you should loose weight. Doing high reps in weight should also burn fat and tone your out so you shouldn't gain a lot of weight, if you are then maybe you should reconsider your workout plan and or your diet.
Well, muscle weighs more than fat, so that COULD be it. But usually you should see weight-loss when you're doing cardio. Could it be that maybe sub-conciously you're allowing yourself to eat more since you've added the exercise in? You should measure yourself, and see if you lose any inches. If you do, but your scales says other-wise, than you'll know it's just muscle.