ASP.NET radio button change

I am trying to figure out why this code doesn’t fire the radio button change event.

here’s the ASP page code for 2 radio buttons

  <asp:RadioButton ID="rdoButton1" GroupName="Group1" Text="Yes" Value="Yes"  runat="server" OnCheckedChanged="Group1_CheckedChanged" />
  <asp:RadioButton ID="rdoButton2" GroupName="Group1" Text="No" Value="No" runat="server" OnCheckedChanged="Group1_CheckedChanged" />

And here’s the code behind:

protected void Group1_CheckedChanged(Object sender, EventArgs e)
{
    if (rdoButton1.Checked) {
        panel1.Visible = true;
    }

    if (rdoButton2.Checked) {
        panel1.Visible = false;
    }
}

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You’ll need to specify the attribute and value AutoPostBack="true" in order to tell ASP.NET that changing of that element should trigger a postback. It should be applied to each individual RadioButton which you wish to cause a postback.

Method 2

You should add the AutoPostBack=True attribute to both controls.

Method 3

you have to specify the AutoPostBack=True for both controls

Method 4

I would use RadioButtonList instead. And set AutoPostBack=true for what you want to do.

Method 5

You should set the AutoPostBack = True and in the code behind the handles in your function.

Example:

Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)           Handles RadioButton1.CheckedChanged


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x