Why is the work done by a block into a spring the same from the work done by the spring on the block? In the following situation:

A 700 g block is released from rest at height h 0 above a vertical
spring with spring constant k = 400 N/m and negligible mass. The block
sticks to the spring and momentarily stops after compressing the
spring 19.0 cm. How much work is done (a) by the block on the spring
and (b) by the spring on the block?

When thinking about the work done by the block on the spring. The block pushes against the spring for a displacement of $ x = 19\cdot10^{-2} m $.
In my understanding, the work done by the block into the spring is $ W = mgx $ as the block is using its weight to press against the spring and produces a displacement, $ x $.
And, on the other side, the work done by the spring on the block is $ W = -\frac{1}{2}kx^2 $
However, in some solutions, I'm finding that "the work done on the spring is the same as the work done in the spring by the block as is an isolated system and there's no dissipation of energy". I'm confused by this.
Why the work is the same?
 A: 
However, in some solutions, I'm finding that "the work done on the spring is the same as the work done in the spring by the block as is an isolated system and there's no dissipation of energy". I'm confused by this.
Why is the work the same?

Work is done by forces, not by objects. The language of "work done on one object by another" is really a shorthand way to specify that we are looking at the work done by the force that one object exerts on another.
By definition, the work done by a force $\mathbf F$ is, $W=\int\mathbf F\cdot\text d\mathbf x$. If we are comparing the work done on the spring by the block to the work done on the block by the spring, we are looking at $W_1=\int\mathbf F_{\text{block}\to\text{spring}}\cdot\text d\mathbf x$ and $W_2=\int\mathbf F_{\text{spring}\to\text{block}}\cdot\text d\mathbf x$ respectively. However, by Newton's third law, $\mathbf F_{\text{block}\to\text{spring}}=-\mathbf F_{\text{spring}\to\text{block}}$, and hence $W_1=-W_2$. This is true of any action-reaction pair; the work done by one force is the negative of the work done by the other force.
When your source says the work is the same, they are probably thinking in terms of absolute values. I personally don't agree with saying the work is the same, even if they are the same in magnitude, but that at least explains the imprecise terminology being used.
A: 
"the work done on the spring is the same as the work done in the spring by the block as is an isolated system and there's no dissipation of energy". I'm confused by this.
Why the work is the same?

This comes directly from the conservation of energy. $\Delta U = Q - W$ where $\Delta U$ is the internal energy of the system, $Q$ is the energy that comes in to the system as heat, and $W$ is the energy that leaves the system as work.
Since there is no dissipation we have $Q=0$ for both the spring and the block. Since the spring and block system is isolated we have $\Delta U_{system}=\Delta U_{spring}+\Delta U_{block} = 0$. Then just by substitution $-W_{spring}-W_{block}=0$ so the work done by the spring on the block is equal and opposite the work done by the block on the spring.
