I used to only award XP and allow level advancement "in town." And sometimes (usually) I would wait until the end of a given storyline/adventure. I have discovered (as a player) that this sucks.
So, award XP every game session, no matter what. If someone levels up, let them have the level up even if they are in the middle of a dungeon crawl.
Seeing your character advance in level is one of the big rewards of DnD (and most RPGs). Why force someone to delay that gratification for "story" reasons, or "realism"? It's a freaking game, it's supposed to be fun. Levelling up is fun.
Don't award XP in mid-session. Levelling up should be done between games to ensure the most possible play time (not book keeping) at each session.