Ballots are secret and voters have the right to vote for any candidate they want.
The only time that party affiliation is important in terms of voting is in the case of a political party caucus or a primary election. In those cases, voters must be registered with the political party whose caucus or primary they wish to participate in. Voters have the right to change their affiliation and then participate in the caucus or primary election on, or prior to, the day those events are being held. Voters can only participate in one party's caucus or primary election each time those events take place.