The dependence of dijet production on the virtuality of the exchanged photon, Q^2, has been studied by measuring dijet cross sections in the range 0 < Q^2 < 2000 GeV^2 with the ZEUS detector at HERA using an integrated luminosity of 38.6 pb^-1. Dijet cross sections were measured for jets with transverse energy E_T^jet > 7.5 and 6.5 GeV and pseudorapidities in the photon-proton centre-of-mass frame in the range -3 < eta^jet <0. The variable xg^obs, a measure of the photon momentum entering the hard process, was used to enhance the sensitivity of the measurement to the photon structure. The Q^2 dependence of the ratio of low- to high-xg^obs events was measured. Next-to-leading-order QCD predictions were found to generally underestimate the low-xg^obs contribution relative to that at high xg^obs. Monte Carlo models based on leading-logarithmic parton-showers, using a partonic structure for the photon which falls smoothly with increasing Q^2, provide a qualitative description of the data.