views:

303

answers:

2

I've got a check for the first radiobutton in my group of ASP.NET radiobuttons. For some reason, the page loads and that first button is automatically checked, not that we're setting it to be checked..it must naturally check itself since it's the first in the group.

However, when I actually check that it's checked in an if statement (so that I can act on it) it returns false even though it's checked for sure when the page renders

myRadioButton.Checked ends up with false. Not sure why.

A: 

My dollars are that you're setting the button state during Page_Load and forgetting to check whether IsPostBack is true/false. Your code likely looks like this:

Page_Load(...) {
  SetFormState()
}

When it should look like this:

Page_Load(...) {
    if (!IsPostBack) {
      SetFormState()
    }
}
Gavin Miller
As I mentioned, we are not setting the default selected radio button anywhere in our code
CoffeeAddict
+1  A: 

ended up being a logic problem. I was binding after my check logic.

CoffeeAddict