$g$ is a measurable function and $X$ and $Y$ are continuous random variables, we need to show that:
$E[(Y-E[Y|X])*(E[Y|X]-g(X))]=0$
My attempt:
$E[(Y-E[Y|X])*(E[Y|X]-g(X))]=E[E[(Y-E[Y|X])*(E[Y|X]-g(X))|X]]$
$(Y-E[Y|X])*(E[Y|X]-g(X))=Z$, where Z is a random variable.
$E[Z|X]=h(X)$ and $E[E[Z|X]]=E[h(X)]=\int_{-\infty}^{+\infty} h(x)f_X(x)dx=\int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty}z \frac{f_{X,Z}(x,z)}{f_X(x)} dz f_X(x)dx$.
If I go down this road, all I get is $E[h(X)]=E[Z]$ which is true but does not take me where I want to.
Any hints?
More generally, $$ \mathrm{E}[(Y-\mathrm{E}[Y\mid X])\cdot Z]=0 $$ for any $\sigma(X)$-measurable random variable $Z$. Use this with $Z=\mathrm{E}[Y\mid X]-g(X)$.
To show the claim just note that the expectation, by the tower property, can be written as $$ \mathrm{E}[\mathrm{E}[(Y-\mathrm{E}[Y\mid X])\cdot Z\mid X]]=\mathrm{E}[Z\cdot\mathrm{E}[Y-\mathrm{E}[Y\mid X]\mid X]]=0. $$