The way I learned was to visualize four important reference points: the open strings and the 5th, 7th, and 12th frets.
Open strings are obvious. You need to learn them. Duh.
12th fret is the octave, where the pattern repeats exactly. If you learn all the notes from frets 0-11, then you automatically know the notes from fret 12 and up, right?
7th fret is the octave of the lower string: 7th fret A string is one octave above open E string; 7th fret D string is one octave above open A string; 7th fret G string is one octave above open D string.
5th fret is the unison of the higher string: 5th fret E string is same as open A string; 5th fret A string is same as open D string; 5th fret D string is same as open G string.
Putting it all together: You are never more than 3 frets from an E, A, D, or G. For example, picking a note at random.... 9th fret E string. I know the 12th fret E string is E, so I count down: E, Eb, D, and the answer is Db (or C#). Another example: D string 8th fret, let's see, I know the 7th fret is A, so I count up, the answer must be Bb.
Learn those reference points (or whichever reference points work best for you) and then you can easily find any other note in relation to those references.