As soon as you realize you're stranded, you may feel a natural urge to panic. However, you have to tell yourself to put mind over matter, and to stay as calm as possible. If you start panicking, your body will start to feel the effects, and you'll only be making it more difficult for yourself to think clearly, and therefore making it harder for you to find a way to escape.
Take a deep breath and relax your body. It is hard for your mind to be in panic when your body is relaxed.
If you're not alone in the elevator, then panicking is more likely to make the people around you panic. And having multiple people freaking out in an elevator is not the way to safety. Instead, do your best to be a calming presence to the people around you.