RadioButtonList OnSelectedIndexChanged

I am looking for the best way to handle index changes selected in ASP.net RadioButtonList (C # code). I have 3 list items. For the first, I want it to display a hidden asp: textbox on the page, while the other 2 hid the text box.

//asp.net side <asp:RadioButtonList ID="_indicatorAckType" runat="server" RepeatDirection="Horizontal" enabled="true" OnSelectedIndexChanged="onAckTypeChanged"> <asp:ListItem Text="None" /> <asp:ListItem Text="SHOW" /> <asp:ListItem Text="HIDE" /> </asp:RadioButtonList> //code behind protected void onAckTypeChanged(object sender, EventArgs e) { if (_indicatorAckType.SelectedItem.Text == "SHOW") _myTextboxID.Visible = true; else _myTextboxID.Visible = false; } 

At first I tried using onclick event handlers, but I was told that ListItem cannot use onclick events with switch elements. What am I doing wrong here? This does not cause any errors or has obvious problems. I tried to make onSelectedIndexChanged do nothing but show a text field, and this also does not work.

Any help is appreciated! Thanks to everyone.

+8
c # event-handling radiobuttonlist
source share
3 answers

In RadioButtonList, set the AutoPostBack attribute to true.

+21
source share

Look at this, it can help. And I suggest disabling autorun if enabled on the radio button to do all this on the client side using jquery.

Example:

Using jQuery, hide the text box if the radio button is selected.

+1
source share

Do you need to do something to refresh the display? Are you sure of the order in which these events are fired in relation to any postback?

+1
source share

All Articles