Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET radio button change

Tags:

c#

asp.net

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;
    }
}
like image 736
Victor Avatar asked Nov 11 '11 14:11

Victor


4 Answers

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.

like image 106
Grant Thomas Avatar answered Oct 20 '22 11:10

Grant Thomas


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

like image 39
Davide Piras Avatar answered Oct 20 '22 12:10

Davide Piras


you have to specify the AutoPostBack=True for both controls

like image 32
Glory Raj Avatar answered Oct 20 '22 10:10

Glory Raj


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

like image 29
Junaid Avatar answered Oct 20 '22 11:10

Junaid