Could be a bad power adapter. Dell laptop power adapters are notoriously unreliable and prone to fail in unpredictable ways; I have seen many. Hope it's the power adapter, as you can buy a generic replacement off eBay for about $8 USD shipped. If it's a motherboard power problem, you are in for a much more expensive repair, most likely.

Here's why I suspect a bad power supply: when you are charging the battery *AND* using it, you are drawing the most current through the power supply. (And the battery won't charge unless charge level drops below a certain threshold.) Dell laptops are designed to charge the battery just as quickly when in use than when powered off (unlike some e.g. some model Toshiba laptops which will charge the battery very slowly when in use but quickly when off). So charging + using puts the biggest load on the supply. This also seems to cause weird issues with failing power supplies; sometimes the laptop will complain that it can't recognize the type of charger anymore and just refuse to charge the battery (but will run the laptop).

Your E5420 seems to use a generic Dell PA-12 (65W) or PA-10 (90W) power adapter, if you want to risk $8 and try a new one. Get the PA-10 to be safe, you can't have too much power, you can only have not enough...