Why?

When things go wrong in our life, many tend to ask "why" God allowed it to happen. How can we have joy in our life when we are faced with trials, and what does God want us to learn from them?