How to get your 14 month old to not kick while changing diaper

My son always kicks me as I change his diaper and it hurts!! Today I slapped him on his leg when he kicked me and sternly said “no kicking!”- he laughed, and then continued doing it. Is it wrong to have slapped him? How should I go about this next time? (I will admit I felt bad after).