It's the best way to get their name without even asking for it. Typically, they will enter both their first and last names, along with their number. It's a great way to stay in touch with them in the future and also to assure you won't forget their name again.
Ask for their email address.
Most people have their name within their email address, so it's an easy way to learn the information you need and gain a valuable connection. It will also show you care about reaching out to them in the future.
If they don't have their name, they might at least have a reference to their college, workplace, or favorite hobby within their username, so it can serve as a great conversation starter.
Introduce them to a friend.
At a party or networking event, making introductions is expected. Find one of your friends and introduce them first, then wait for your conversation partner to do the same.
Wait until the conversation ends, and ask a friend.
Oftentimes, you can go through an entire conversation simply using pronouns. There's always someone else at the party who must have either invited this person or who is in the same network — ask them afterwards.
They will appreciate your honesty, because everyone understands it's difficult to remember names. Just politely and apologetically admit that it slipped your mind or that it's on the tip of your tongue but you can't think of it now.