$\int _\Omega \nabla f \nabla u =\int _\Omega \nabla g \nabla u$ for all $u\in H^{1,0}$ implies $f=g+\text {const}$? Suppose $\Omega$ is a bounded and open set in $\mathbb R^n$. Consider functions $f,g\in H^{1,0}(\Omega):=W^{1,2}(\Omega)$ such that $\int _\Omega \nabla f  \nabla u =\int _\Omega \nabla g \nabla u$ for all $u\in H^{1,0}(\Omega)$. (This equality is derived from a statement I proved regarding Neuman problem).
Is it possible to show that $f=g+\text {const}$? I took $u$ to be the identity and then tried to show that $\int _\Omega \nabla f=\int _\Omega \nabla g$ implies $f=g+\text {const}$. But I was corrected that it is not true. Any other ways?
 A: This is true if $\Omega$ is connected.  Otherwise, it's not true.  (Let $f = 1$ on one component, $f = 0$ on another component, then set $g = 0$ where $f = 1$, and $g = 1$ where $f = 0$, etc.)  
First, observe that if $\nabla f = \nabla g$ a.e. on $\Omega$ and $\Omega$ is connected, then $f - g$ is constant.  This is because a function in $H^{1}(\Omega)$ with vanishing derivative is necessarily constant.  (This can be proved using mollifiers, for example.)
Next, observe that $\nabla f = \nabla g$ a.e. if and only if, for each $i$, $\frac{\partial f}{\partial x_{i}} = \frac{\partial g}{\partial x_{i}}$ a.e.  Now we can make use of the fact that in one dimension, continuous functions have anti-derivatives.  
Fix $i \in \{1,2,\dots,n\}$, $x \in \Omega$, and $r > 0$ such that $$\{y \in \mathbb{R}^{n} \, \mid \, \forall j \in \{1,2,\dots,n\} \, \, |y_{j} - x_{j}| < r\} \subseteq \Omega.$$  Define $\varphi : \mathbb{R}^{d} \to \mathbb{R}$ by $$\varphi(y) = \left\{ \begin{array}{r l} y_{i} - x_{i}, & |y_{i} - x_{i}| < \frac{r}{2} \\
\frac{r}{2}, & y_{i} - x_{i} \geq \frac{r}{2} \\
- \frac{r}{2}, & y_{i} - x_{i} \leq \frac{r}{2}
\end{array} \right.$$
Observe that $\varphi \in L^{2}(\Omega)$ since $\Omega$ is bounded and 
$$\nabla \varphi(y) = \left\{\begin{array}{r l} (0,0,\dots,0,1,0,\dots,0), & |y_{i} - x_{i}| < \frac{r}{2} \\
0, & \text{otherwise.} \end{array} \right.$$
Thus, $\nabla \varphi \in L^{2}(\Omega)$, which shows that $\varphi \in H^{1}(\Omega)$.  
Let $B_{r}(x) = \{y \in \mathbb{R}^{n} \, \mid \, \forall j \in \{1,2,\dots,n\} \, \, |y_{j} - x_{j}| < \frac{r}{2}\}$.  Then 
$$\int_{B_{r}(x)} \frac{\partial f}{\partial x_{i}}(y) \, dy = \int_{B_{r}(x)} \nabla f(y) \cdot \nabla \varphi(y) \, dy = \int_{B_{r}(x)} \frac{\partial g}{\partial x_{i}}(y) \, dy.$$
Divide by $\left(\frac{r}{2}\right)^{d}$ and appeal to the Lebesgue Differentiation Theorem to obtain:
$$\frac{\partial f}{\partial x_{i}}(x) = \frac{\partial g}{\partial x_{i}}(x) \quad \text{a.e.}$$
Edit:  Jeff mentioned a much easier proof in the comments.  It's worth reproducing here.  Set $u = f - g$.  Then $\nabla u = \nabla f - \nabla g$ and, thus,
$$\int_{\Omega} \nabla f(y) \cdot (\nabla f(y) - \nabla g(y)) \, dy = \int_{\Omega} \nabla g(y) \cdot (\nabla f(y) - \nabla g(y)) \, dy.$$
Subtracing one side from the other and using linearity of the integral and inner product, we obtain
$$\int_{\Omega} \|\nabla f(y) - \nabla g(y)\|^{2} \, dy = 0.$$
Since $y \mapsto \|\nabla f(y) - \nabla g(y)\|^{2}$ is a non-negative measurable function, this proves $\|\nabla f(y) - \nabla g(y)\|^{2} = 0$ a.e.  In particular, $\nabla u = 0$.  As I remarked above, we conclude $u = 0$.  Therefore, $u = f - g$ is a constant.
