Yes, speaking assertively when you feel disrespected is a strategy to stop.
Assertiveness is a skill regularly referred to in social and communication skills training. Being assertive means being able to stand up for your own or other people's rights in a calm and positive way, without being either aggressive, or passively accepting 'wrong'.