Dirichlet Principle in Sobolev Spaces According to Zeidler, 1995, in his book "Applied Functional Analysis: Application to Mathematical Physics".
Dirichlet problem is a problem to minimize $$F(u)=\frac{1}{2}\int_G(u')^2\ dx-\int_G fu\ dx,\qquad u=g \textrm{ in } bd(G).$$
Then, He says

If $G$ is open, bounded, nonempty subset of $\mathbb{R}$ and given
  continuous functions $f:G\rightarrow\mathbb{R}$ and
  $g:bd(G)\rightarrow\mathbb{R}$. Then, for $u\in C^2(\overline{G})$:
$1.$ If $u$ is solution to Dirichlet problem then $u$ is also a
  solution to generalized boundary value problem $$\int_G u'v'\ dx=\int_G fv\ dx,\qquad\forall v\in C_0^\infty(G)$$ $2.$ $u$ is a
  solution to boundary value problem $$-u''=f,\qquad \textrm{in } G$$
  $$u=g,\qquad \textrm{in }\partial G$$ if and only if $u$ is a solution
  to generalized boundary value problem $$\int_G u'v'\ dx=\int_G fv\ dx,\qquad\forall v\in C_0^\infty(G)$$

After that, he gives explanation that there is a Dirichlet problem which doesn't have solution (so Dirichlet Principle can't be justified). What I know about this, later on, is that the solution space needs to be complete so the Dirichlet Principle can be justified.
Therefore, the Dirichlet problem needs to be generalized by introducing Sobolev Space $W_2^1(G)$. The generalized Dirichlet Problem is to minimize the function $$\frac{1}{2}\int_G (\partial u)^2\ dx-\int_G fu\ dx, \qquad u-g\in \overset{\circ}{W^1_2}(G),$$ where $\partial u$ denotes weak derivatives of $u.$
The Dirichlet Principle is stated as below:

If $G$ is open, bounded, nonempty subset of $\mathbb{R}$. Given two
  functions $f\in L_2(G)$ and $g\in W_2^1(G)$. Then, these are true:
$1.$ The Generalized Dirichlet Problem has a unique solution $u\in W_2^1(G).$
$2.$ Solution to Generalized Dirichlet Problem is also a solution to
  generalized boundary value problem $$\int_G \partial u \partial v \ dx=\int_G fv \ dx,\qquad \forall v\in \overset{\circ}{W^1_2}(G), \textrm{ and }u-g\in \overset{\circ}{W^1_2}(G)$$

My questions are:


*

*Why the solution space $C^2(G)$ is generalized to $W_2^1(G)$? $C^2(G)$ is SECOND order continuously differentiable functions space while $W_2^1(G)$ is FIRST order weak derivable functions space.

*Why the given function $g$ is generalized from only in $C(bd(G))$ to $W_2^1(G)$? The domain is extended from $bd(G)$ to $G$.

*When proving the Dirichlet Principle, Zeidler, uses a theorem called Theorem in Quadratic Variational Problem, which only solved the minimizing problem and not the boundary condition, Why?
Note: Please help me. This is my undergraduate thesis topic and my undergraduate thesis defense seminar will be conducted on next Tuesday. Nobody familiar with this topic in my campus. So please, I'm desperately need an answer. Anything. Any explanation.
 A: Let me try to explain. If you have a solution $u \in C^2(G)$ of the equation $-u''=f$ in $G$, then for any $v \in C_c^\infty(G)$ an integration by parts shows that $$\int_G u' v' = \int_G f v.$$ Notice that there is no reference to the value of $u$ on $\partial G$, since $v$ vanishes on $\partial G$ and the boundary terms in the integration by parts disappear no matter how $u$ in defined on the boundary of $G$.
Now you define weak solution any element $u \in X$, $X$ being a suitable function space, such that
$$\int_G u' v' = \int_G f v$$
for any $v \in C_c^\infty(G)$. Now, how do you choose $X$? You have much freedom, but $u'$ should be meaningful (in some sense), and the boundary condition $u=g$ on $\partial G$ should be included.
It turns out that $X=g+ W_0^{1,2}(G)$, often written $g+H_0^1(G)$, is a good choice. As Zeidler says, everything works.
Your questions remain valid, in particular the second one: why should we extend $g$ to the whole $\bar{G}$, if we need it only on the boundary of $G$? You are right, but an answer would rely on the theory of traces in Sobolev spaces, which is a difficult topic.
Moreover, it can be proved that any weak solution is a classical $C^2$ solution as soon as  $f$ is continuous up to the boundary of $G$. It is rather easy in 1D (i.e. in $\mathbb{R}), while it is really hard in higher dimension. I suggest that you read carefully the chapter devoted to Sobolev spaces in 1D in the book by Haim Brezis, Functional analysis. You'll find a more detailed explanation of the road from classical to weak solutions and viceversa.
A: I'll try to hint on answers to your first and second question.
Ad 1. As my comment suggested, the $C^2$ regularity of $u$ is needed to give sense to the term $-u''=f$. If you consider the generalized boundary value problem only first order derivatives appear. Essentially, this is the reason why only $W^{1,2}$ functions are considered in the second problem.
Ad 2. In the generalized setting one requires a definition of boundary values of $W^{1,2}$ functions. An easy way is to consider boundary data that are in some sense inherited by $W^{1,2}$-functions. Here the so-called trace theorem comes into play.
