Essex 367 for 7 (ten Doeschate 120*, Bopara 64, Footitt 3-82) trail Surrey 399 (Stoneman 197, Sibley 69, S Curran 65, Porter 4-102) by 32 runs
Ryan ten Doeschate's first hundred of the season put Essex in a good position after another day of heavy run scoring against Surrey at Guildford.
The Essex captain has struggled to recapture the form he showed last season when he scored 1,226 runs with four centuries, but he finished unbeaten on 120 with Essex 367 for 7 in reply to Surrey's 399.
He came in when his side were in a spot of bother. Surrey skipper Gareth Batty had taken two quick wickets to reduce Essex to 134 for 4, but Ravi Bopara helped ten Doeschate rebuild the innings with a stand of 120 in 27 overs, of which Bopara contributed 64, his first half-century of the season.
Ten Doeschate had a life on 37 when wicketkeeper Ben Foakes put down a difficult chance down the leg side but grew in confidence as he built his innings, playing authoritative shots on both sides of the wicket. A leg glance off Stuart Meaker took him to his hundred, off 120 balls, and by stumps he had faced 144 balls and hit a six and 18 fours.
Surrey's attack stuck to their task throughout and there were moments in the day when they looked to be in control. Sam Curran had Alastair Cook lbw with a touch of late inswing on the stroke of lunch and after Tom Westley was squared up by Mark Footitt, Batty struck twice with Nick Browne lbw working to leg and Dan Lawrence cutting straight to point.
But Bopara and ten Doeschate took advantage of quick-scoring conditions to build a useful partnership which ended when Stuart Meaker returned to the attack and found a touch of reverse swing to pin Bopara, offering no shot, having hit nine fours and two sixes.
Footitt returned to pick up James Foster and Simon Harmer but Neil Wagner helped ten Doeschate add 41 for the eighth wicket on a day when 413 runs were scored.
Earlier, Mark Stoneman completed a career-best 197 but just missed out on a maiden double hundred. The left-hander resumed on 181 and scored the seven he needed to take him past his previous best, made for former county Durham against Middlesex in 2014.
Essex wicketkeeper Foster dived in front of slip to take the edge after Stoneman made his first mistake, driving outside off stump at a delivery from Wagner he could have ignored. He faced 248 balls and hit two sixes and 26 fours.
Batty drove to point off Bopara before Jamie Porter switched ends to finish the innings when he picked up Ravi Rampaul and Footitt in five balls as Surrey lost their last four wickets in four overs for seven runs.