I guess probably everyone has gotten lost in a solo at some point in their lives - the thing that separates the good players from the not-so-good is how they handle it.
I read an interview with BB King a while back, and one of the questions he was asked was "What do you do if you lose your place in the chords while you're soloing?"
BB's answer was that he plays whole notes.
He looks for a note that is within the chord (chords are made up of individual notes) and then he just holds that note until the progression moves back to a place he recognizes.
For instance, in a G chord, you've got three notes: G, B and D.
Play any one of those notes and it is going to sound great against the chord... it blends right into the chord.
With this trick, 9 times out of 10, no one is ever going to realize you didn't know exactly what you were doing there.
That's just one simple example of how guitar theory can really play a big role in your on-the-spot playing ability.
A lot of people think guitar theory is simply head knowledge, but in reality it can make the difference between a great solo and a total flop.
I'm not talking about learning how to read music here - I'm talking about the nuts and bolts theory that BB King was talking about - things like what notes go into what chords, why chords work together, how chords and scales and keys all relate to each other... that kind of thing.
To learn guitar theory the easy way, checkout the Unlocking I IV V course.
Don't forget that whole note trick, it just might save your bacon one day!