Some laptops are set up that way. Try turning off the laptop (not sleep or hibernate, but off) and see if it will charge then.
If not, then either the battery you got isn't right for your device. If it is an aftermarket battery that is completely possible. Or, your charging circuit might be bad.
However if it will charge when turned off, just not when turned on, then it is the charging cord that needs replacing. If they are damaged (even if you can't see it) they can be not allowing enough power to get through and both power the device and charge the battery.