A multiwavelength study of an M-class flare and the origin of an associated eruption from NOAA AR 11045