I feel like this is a pile of you know what I mean. It works but I feel like I'm way overdoing this in terms of the page lifecycle (load and postbacks) and even the redundancy I have in each of the if statements here.
What happens is this:
- This method is called on very page load (no matter if postback or whatever)
- If the user submits the form it reduces their totalPoints (there's a button below these radiobuttons that allow them to submit and claim points).
So I call this method also right after the users claims point (submits) which drops those points from their total for next time around. So based on the total points in their account, I need to enable/disable these radio buttons after the page refreshes from the last submit
private void SetPointsOptions()
{
int totalPoints = customer.TotalPoints;
rbn200Points.Text = "200 pts";
rbn250Points.Text = "250 pts";
rbn400Points.Text = "400 pts";
rbn500Points.Text = "500 pts";
rbn600Points.Text = "600 pts";
// clear state of radio buttons & disable submit
if (totalPoints < 200)
{
rbn200Points.Enabled = false;
rbn250Points.Enabled = false;
rbn400Points.Enabled = false;
rbn500Points.Enabled = false;
rbn600Points.Enabled = false;
rbn200Points.Checked = false;
rbn250Points.Checked = false;
rbn400Points.Checked = false;
rbn500Points.Checked = false;
rbn600Points.Checked = false;
btnClaimRewardPoints.Enabled = false;
return;
}
if(totalPoints >= 200 && totalPoints < 250)
{
rbn200Points.Enabled = true;
}
else if(totalPoints >= 250 && totalPoints < 400)
{
rbn200Points.Enabled = true;
rbn250Points.Enabled = true;
}
else if(totalPoints >= 400 && totalPoints < 500)
{
rbn200Points.Enabled = true;
rbn250Points.Enabled = true;
rbn400Points.Enabled = true;
}
else if(totalPoints >= 500 && totalPoints < 600)
{
rbn200Points.Enabled = true;
rbn250Points.Enabled = true;
rbn400Points.Enabled = true;
rbn500Points.Enabled = true;
}
else if(totalPoints >= 600)
{
rbn200Points.Enabled = true;
rbn250Points.Enabled = true;
rbn400Points.Enabled = true;
rbn500Points.Enabled = true;
rbn600Points.Enabled = true;
}
}