On a NetwebForm
in a string type field with an autocomplete and a lookup button
you can set the field to readonly with a condition eg. gsv('aaa') <> 'aaa'
However if you put the same check in the hide lookup button template code a complie error occurs