MANCHESTER, N.H. — Republican Presidential hopeful Rick Santorum again waded into the same-sex marriage controversy on the campaign trail in New Hampshire, suggesting to students at a private school that an imprisoned father is better than a gay dad — just hours after being aggressively heckled at another campaign stop.

At a town hall meeting at a college prepatory school in Dublin, N.H., students repeatedly questioned Santorum about his position on same-sex marriage.

“You’re robbing children of something that they need, they deserve, they have a right to. They have a right to be know and be loved by their dad or their mom,” Santorum told the students.

“Marriage is not a right,” Santorum said. “It’s a privilege that is given to society by society for a reason … We want to encourage what is the best for children.”

Santorum said it was critical for children to have both a father and mother and that even an imprisoned father was preferable to a same-sex parent.

Citing an anti-poverty expert, Santorum said, “Even fathers in jail who had abandoned their kids were still better than no father at all to have in their children’s lives.”

The audience, half students and half local residents, reacted with snorts and applause.

The students at Dublin School, which runs from ninth through 12th grade, were primed for Santorum’s visit, said headmaster Brad Bates. He said three students in the audience had gay parents, though they were not among those who asked about the topic.

Earlier in the day, Santorum was aggressively heckled at a campaign stop in the parking lot of a Manchester restaurant, with the barbs appearing to come from a combination of gay rights activists, Ron Paul supporters and Occupy Wall Street protesters.

According to The Washington Post, the wild scene included a crush of protesters, some carrying signs that read “Marry Me Rick” and “Google Santorum” — a reference to a redefined internet definition of the senator’s last name that comes up on the search engine.

Santorum was interrupted periodically by heckles, particularly one man who shouted every few minutes.

“What about equality for the gays?” he yelled at one point and, after Santorum opened with a request for respect, “How much respect for you have for gay people, Rick!”

On Thursday, Santorum was met with boos by a group of college students when he compared same-sex marriage to polygamy.

The often testy exchange occurred as Santorum addressed the College Convention 2012, a forum organized by New England College and open to students from all over the state.

“If you’re not happy unless you’re married to five other people, is that O.K.?” asked Santorum, to which the audience booed. “What about three men?” continued Santorum.

Santorum’s combative stance against gay rights — particularly his remark during a 2003 interview that gay marriage is no different from “man on child, man on dog, or whatever the case may be” — have distinguished him as a hero of those who oppose gay rights and brought him a passel of trouble from activists who support them, commented the Los Angeles Times on Friday.

The former Pennsylvania senator has been a conservative crusader on social issues, which had far more political resonance in Iowa than in New Hampshire.

Same-sex marriage has been legal in New Hampshiree since 2010.