Have you tried turning it off and on?
Depends a lot on what device you're talking about.
If it's an iPhone 3G or 3GS, you can open it up and check the connector, but if it were loose, it would also probably affect your sleep button and headphone jack. If opening it and pushing down the connector didn't fix it, the flex cable is probably shot and should be replaced.
If its a 4 or 4S, open it up and check the flex cable connector to those buttons. I don't remember if the cable is shared with anything else in those models. Same advice as above, though.
If its an iPad, I'm sure the steps are similar, but you'll probably need to buy a new set of fastening clips, since a few usually get broken when disassembled.
You might want to try a restore (without using a backup) and see if it is a wonky setting before taking it apart.