Just changed light fixture. When I put the power back on the light worked but the switch on the wall will not shut the light off.

In the ceiling there was 3 wires. One black,one white and one red. The fixture that I put up has only black, white and ground. So I attached the black to black, white to white and the ground to the grounding post. The red I just capped off. Now the power is getting to the fixture and it works, but I can not shut the light off by the switch.

I looked at the wall switch and it has a red wire hooked up to the switch on the top and black wires hooked on the bottom of the light switch.

Why is the wall switch not working? Should I have attached the red wire in the ceiling to the black wires? Would that work?

Please help. I have changed lights before but always there has only been black and white wires to attach.

Thanks in advance.